Java maven shade插件中的清单不起作用 目标:创建构建编号并将其放入maven shade插件生成的清单中。然后,读那个构建编号。
我使用了Java maven shade插件中的清单不起作用 目标:创建构建编号并将其放入maven shade插件生成的清单中。然后,读那个构建编号。,java,maven,maven-shade-plugin,Java,Maven,Maven Shade Plugin,我使用了ManifestResourceTransformer,并在那里声明了manifestEntries <!-- Maven Shade Plugin --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <version>2.4.2
ManifestResourceTransformer
,并在那里声明了manifestEntries
<!-- Maven Shade Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.2</version>
<executions>
<!-- Run shade goal on package phase -->
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>app.MainApp</mainClass>
<manifestEntries>
<Implementation-Build>${buildNumber}</Implementation-Build>
</manifestEntries>
</transformer>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
结果
为了更好地衡量,我甚至硬编码了版本号
<manifestEntries>
<Implementation-Build>123123</Implementation-Build>
</manifestEntries>
123123
结果还是一样
想法:清单看起来确实像默认清单,而不是任何东西。
编辑:我的pom文件:
4.0.0
MyGroupId
MyArtifactId
MyApp
scm:git:https://github.com/myorg/myrepo.git
scm:git:https://github.com/myorg/myrepo.git
发展
https://github.com/myorg/myrepo.git
src
src
**/*.爪哇
资源
**/*.爪哇
org.apache.maven.plugins
maven阴影插件
2.4.2
包裹
阴凉处
app.MainApp
${buildNumber}
*:*
META-INF/*.SF
META-INF/*.DSA
META-INF/*.RSA
maven编译器插件
3.3
1.8
1.8
org.codehaus.mojo
buildnumber maven插件
1.4
验证
创造
{0,日期,yyyyMMddHHmmss}
时间戳
真的
真的
com.github.github
SiteMaven插件
0.9
网站
站点部署
github
为我的项目构建站点
${site.path}
真的
4thline回购
http://4thline.org/m2
假的
clojars.org
http://clojars.org/repo
com.thoughtworks.xstream
xstream
1.4.7
...
如何运行附加的代码?如果将其作为测试运行,它将生成输出,因为测试类路径不包括MANIFEST.MF文件。您需要在类路径中包含生成的(+阴影)jar,以便运行该代码。pom文件不完整,缺少重要内容……除此之外,您为什么更改默认文件夹位置?你们有什么样的包装?遗漏了重要的东西,比如?我故意不包括诸如……之类的内容。。。除此之外,还有无数的依赖关系。不确定这些是否有用和相关。无论如何,我会编辑一个更完整的pom。我是Maven的新手。我不知道你为什么要更改默认文件夹位置的问题。包装,是罐子。我使用maven shade插件创建了一个大的uber罐。
Manifest-Version : 1.0
Created by : 1.6.0_65-b14-466-11M4802 (Apple Inc.)
Built by : null
Implementation-Build: null
<manifestEntries>
<Implementation-Build>123123</Implementation-Build>
</manifestEntries>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>MyGroupId</groupId>
<artifactId>MyArtifactId</artifactId>
<name>MyApp</name>
<scm>
<connection>scm:git:https://github.com/myorg/myrepo.git</connection>
<developerConnection>scm:git:https://github.com/myorg/myrepo.git</developerConnection>
<tag>DEVELOP</tag>
<url>https://github.com/myorg/myrepo.git</url>
</scm>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<resource>
<directory>resources</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<!-- Maven Shade Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.2</version>
<executions>
<!-- Run shade goal on package phase -->
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<!-- add Main-Class to manifest file -->
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>app.MainApp</mainClass>
<manifestEntries>
<Implementation-Build>${buildNumber}</Implementation-Build>
</manifestEntries>
</transformer>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<format>{0,date,yyyyMMddHHmmss}</format>
<items>
<item>timestamp</item>
</items>
<doCheck>true</doCheck>
<doUpdate>true</doUpdate>
</configuration>
</plugin>
<plugin>
<!-- Deploy the web site -->
<groupId>com.github.github</groupId>
<artifactId>site-maven-plugin</artifactId>
<version>0.9</version>
<executions>
<execution>
<goals>
<goal>site</goal>
</goals>
<phase>site-deploy</phase>
<configuration>
<!-- must match the server's id -->
<server>github</server>
<!-- The commit message -->
<message>Building site for my project</message>
<!-- The location where the site is uploaded -->
<path>${site.path}</path>
<!-- Use merge or override the content -->
<merge>true</merge>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>4thline-repo</id>
<url>http://4thline.org/m2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>clojars.org</id>
<url>http://clojars.org/repo</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.7</version>
</dependency>
...
</dependencies>
</project>