完整的Maven newb在這裏,所以原諒任何濫用的術語等Maven 3 - 在.jar中分發自定義插件?
我已經在Maven 3(定義git rebase的目標之一)中構建了一個自定義插件。我能夠:
mvn install
沒問題。然後我可以從命令行調用目標:
mvn edu.clemson.cs.rsrg:git-plugin:rebase
一切都很好。我有這個可愛的git-plugin-XXX.jar文件,位於我的target
目錄中。
我想讓我的自定義目標可用於另一個項目,這樣當開發團隊的其他成員拉下該項目的源代碼時,他們會免費獲得我的插件(或至少在mvn build
之後)。
我的理解是,純粹的解決方案是爲該組建立一個maven repo,並在那裏加載我的插件,但對於一個單一的hacky插件來說似乎過度。
想法?
我打過通過三種不同的插件做這件事至今:
addjars-maven-plugin:add-jars
<plugin> <groupId>com.googlecode.addjars-maven-plugin</groupId> <artifactId>addjars-maven-plugin</artifactId> <version>1.0.4</version> <executions> <execution> <goals> <goal>add-jars</goal> </goals> <configuration> <resources> <resource> <directory>${basedir}/plugins</directory> </resource> </resources> </configuration> </execution> </executions> </plugin>
讓我在mvn build
這個錯誤:
[ERROR] Error resolving version for plugin 'edu.clemson.cs.rsrg:git-plugin' from the repositories [local (/home/hamptos/.m2/repository), central (http://repo.maven.apache.org/maven2)]: Plugin not found in any plugin repository
這也導致我以後的格式化插件失敗。 (?顯然它是閱讀的罐子和確定的組名/插件名稱,但後來它在我的本地回購去,並期待它當然它不存在 - 我正嘗試安裝它。)
build-helper:attach-artifacts
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>1.7</version> <executions> <execution> <id>attach-artifacts</id> <phase>install</phase> <goals> <goal>attach-artifact</goal> </goals> <configuration> <artifacts> <artifact> <file>${basedir}/plugins/git-plugin-0.1.0a.jar</file> <type>jar</type> </artifact> </artifacts> </configuration> </execution> </executions> </plugin>
讓我在mvn build
這個錯誤:
[ERROR] Failed to execute goal org.codehaus.mojo:build-helper-maven-plugin:1.7:attach-artifact (attach-artifacts) on project RESOLVE: Execution attach-artifacts of goal org.codehaus.mojo:build-helper-maven-plugin:1.7:attach-artifact failed: For artifact {edu.clemson.cs.rsrg:RESOLVE:12.09.01a:jar}: An attached artifact must have a different ID than its corresponding main artifact.
(RESOLVE:12.09.01a是主要項目。很明顯,這裏出現了一些錯誤,因爲插件和主項目肯定有不同的artifactID。試圖將該項目附加在其本身上?)
maven-install-plugin:install-file
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-install-plugin</artifactId> <version>2.3.1</version> <executions> <execution> <id>install-git-plugin</id> <phase>initialize</phase> <goals> <goal>install-file</goal> </goals> <configuration> <file>${basedir}/plugins/git-plugin-0.1.0a.jar</file> <packaging>jar</packaging> <groupId>edu.clemson.cs.rsrg</groupId> <artifactId>git-plugin</artifactId> <version>0.1.0a</version> </configuration> </execution> </executions> </plugin>
似乎做工精細,直到我嘗試調用像mvn edu.clemson.cs.rsrg:git-plugin:rebase
的目標之一,此時它給了我這個錯誤:
[ERROR] Failed to execute goal edu.clemson.cs.rsrg:git-plugin:0.1.0a:rebase (default-cli) on project RESOLVE: Execution default-cli of goal edu.clemson.cs.rsrg:git-plugin:0.1.0a:rebase failed: Unable to load the mojo 'rebase' (or one of its required components) from the plugin 'edu.clemson.cs.rsrg:git-plugin:0.1.0a': com.google.inject.ProvisionException: Guice provision errors: [ERROR] [ERROR] 1) Error in ComponentFactory:ant-mojo [ERROR] at ClassRealm[plugin>edu.clemson.cs.rsrg:git-plugin:0.1.0a, parent: [email protected]] [ERROR] while locating org.apache.maven.plugin.Mojo annotated with @com.google.inject.name.Named(value=edu.clemson.cs.rsrg:git-plugin:0.1.0a:rebase)
要清楚,我說我的插件是哈克開源。我說創建一個存儲庫太過分了。 ;) –
讓我們假設我願意走這條路 - 建立一個相對簡單的存儲庫? –
如果您使用Maven倉庫管理器(nexus,artifactory或archivia)之一,那麼就很容易...噢,朋友不讓朋友在沒有倉庫管理員的情況下使用maven。退出戰鬥maven在這一個...你會失去(注意我是一個maven提交者和項目管理委員會) –