gpt4 book ai didi

java - Maven自定义包装

转载 作者:行者123 更新时间:2023-11-29 05:18:30 24 4
gpt4 key购买 nike

我正在使用一个库 ( RootBeer ),它需要一个额外的构建步骤:在创建我的 JAR 之后,我必须运行 RootBeer JAR 并将我的 JAR 作为其参数来创建最终的启用 RootBeer 的 JAR。

例如,如果我的 jar 是 myjar.jar,这就是我必须使用 RootBeer 创建最终 Artifact myjar-final.jar 的方式:

java -jar rootbeer.jar myjar.jar myjar-final.jar

我想知道 Maven 中是否有一种机制可以让我以这种方式构建 Artifact 。

现在我正在将 gmaven-plugin 与 Groovy 脚本一起使用,但这感觉太老套了,而且我很确定我不能将生成的 Artifact 用作 Maven 依赖项在其他项目中:

<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>

有什么建议吗?

最佳答案

您可以使用 exec-maven-plugin要执行您在 Groovy 中实现的最后一步,您还需要添加 build-helper-maven-plugin将补充 Artifact 添加到 Maven 以使其与您的其余 Artifact 一起部署。

        <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>

关于java - Maven自定义包装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25666182/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com