我正在尝试为 jar 打包 Artifact 和测试 jar 打包创建不同的 MANIFEST.MF
文件。 maven-jar-plugin
用于将其他内容添加到 MANIFEST.MF
- 到目前为止效果很好。但是如果我想为测试项目的 MANIFEST.MF
选择不同的模板文件,Maven 只对两个 Artifact 使用第二个引用的模板......
我怎样才能让 Maven 将 PROD-MANIFEST.MF-template
用于正常的 jar 打包,将 TEST-MANIFEST.MF-template
用于测试- jar 包装?
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>test-manifest-mf</id>
<phase>package</phase>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
<manifestFile>foo/TEST-MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>default-manifest-mf</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
</manifest>
<manifestFile>foo/PROD-MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
最佳答案
包装您在配置文件中提供的每个插件配置。
<profiles>
<profile>
<id>PROD</id>
<build>
<plugins>
// your PROD plugin configuration
</plugins>
</build>
</profile>
<profile>
<id>TEST</id>
<build>
<plugins>
// your TEST plugin configuration
</plugins>
</build>
</profile>
</profiles>
然后您使用配置文件调用 Maven
mvn package -P PROD
希望对您有所帮助。
关于java - 默认 jar 文件和 tests.jar 的不同 MANIFEST.MF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8215360/