在这里填写Maven newb,原谅任何滥用的术语等等。
我在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
它还会导致我以后的格式化插件失败。 (显然它是读取jar并确定了组名/插件名称,但是它会在我的本地仓库中查找它?当然它不存在 - 我正在尝试安装它。)
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.
(决议:12.09.01a是主要项目。显然这里有些东西出了问题,因为插件和主要项目肯定有不同的artifactIDs。试图将项目附加在自己的顶部可能?)
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: sun.misc.Launcher$AppClassLoader@e776f7]
[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)
答案 0 :(得分:0)
你可能认为它是黑客,但它是真正的方式。它需要部署到maven仓库。
如果你把它保存在一个你可以证明拥有它并且它是开源的groupId中你可以publish it to central