我正在使用一个库(RootBeer),这需要一个额外的构建步骤:在创建我的JAR之后,我必须以我的JAR作为参数运行RootBeer JAR,以创建最终启用RootBeer的JAR。
例如,如果我的jar是myjar.jar
,这就是我必须使用RootBeer创建最终的人工制品myjar-final.jar
:
java -jar rootbeer.jar myjar.jar myjar-final.jar
我想知道Maven中是否有一种机制可以让我以这种方式构建工件。
现在我正在使用带有Groovy脚本的gmaven-plugin
,但这只是感觉太乱了,而且我很确定我无法在其他项目中使用生成的artefact作为Maven依赖项: / p>
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<id>groovy-magic</id>
<phase>package</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
println """java -jar target/rootbeer-1.2.0.jar target/myjar.jar target/myjar-final.jar"""
.execute().in.eachLine {
line -> println line
}
</source>
</configuration>
</execution>
</executions>
</plugin>
有什么建议吗?
答案 0 :(得分:3)
您可以使用exec-maven-plugin执行Groovy中已实现的最后一步,此外,您需要添加build-helper-maven-plugin以将补充工件添加到Maven,以便将其与其余工件一起部署
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- The main class of rootbeer.jar -->
<mainClass>org.trifort.rootbeer.entry.Main</mainClass>
<!-- by setting equal source and target jar names, the main artefact is
replaced with the one built in the final step, which is exactly what I need. -->
<arguments>
<argument>${project.build.directory}/${project.artifactId}.jar</argument>
<argument>${project.build.directory}/${project.artifactId}.jar</argument>
<argument>-nodoubles</argument>
</arguments>
</configuration>
</plugin>