I have the following in my project's pom.xml which I think should display the version of Maven being used in the resulting WAR file:
我在我的项目的pom.xml中有以下内容,我认为应该显示在生成的WAR文件中使用的Maven版本:
<build>
...
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<archive>
<manifest>
<addClasspath>false</addClasspath>
</manifest>
<manifestEntries>
<Build-Time>${maven.build.timestamp}</Build-Time>
<Build-Host>${agent.name}</Build-Host>
<Build-User>${user.name}</Build-User>
<Build-Maven>Maven ${maven.version}</Build-Maven>
<Build-Java>${java.version}</Build-Java>
<Build-OS>${os.name}</Build-OS>
<Build-Label>${project.version}</Build-Label>
<Build-Path>${basedir}</Build-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
...
</plugins>
...
</build>
The MANIFEST.MF that is created looks correct see below apart from the Build-Maven line in which the ${maven.version} is not substituted with the actual version number 3.0.4 in this case.
创建的MANIFEST.MF看起来正确,除了在这种情况下$ {maven.version}未替换为实际版本号3.0.4的Build-Maven行之外。
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: stocjon
Build-Jdk: 1.6.0_35
Build-Host:
Build-Java: 1.6.0_35
Build-Label: 1.0.0-SNAPSHOT
Build-Maven: Maven ${maven.version}
Build-OS: Windows XP
Build-Path: C:\Development\project_name
Build-Time: 15:38:50 21-Sep-2012
Build-User: user_name
Any ideas why Maven version is not being populated in the MANIFEST.MF ?
任何想法为什么Maven版本没有在MANIFEST.MF中填充?
Help would be much appreciated.
非常感谢帮助。
Thanks Jon
谢谢乔恩
6 个解决方案
#1
7
You need to add this plugin:
你需要添加这个插件:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>maven-version</goal>
</goals>
</execution>
</executions>
</plugin>
Check here for details.
点击此处了解详情。
#2
7
We no more need the build-helper-maven-plugin since the feature (MSHARED-38) was added to the component maven-archiver : 2.5 in Feb. 2012 (release notes).
我们不再需要build-helper-maven-plugin,因为该功能(MSHARED-38)已于2012年2月添加到组件maven-archiver:2.5(发行说明)。
And this component is used by the Maven plugins like maven-jar-plugin, maven-war-plugin, maven-ear-plugin, etc.
这个组件被Maven插件使用,如maven-jar-plugin,maven-war-plugin,maven-ear-plugin等。
The versions of these plugins using this feature are :
使用此功能的这些插件的版本是:
- maven-jar-plugin : 2.4 (MJAR-148), released in Feb. 2012
- maven-jar-plugin:2.4(MJAR-148),于2012年2月发布
- maven-war-plugin : 2.2 (MWAR-273), released in Feb. 2012
- maven-war-plugin:2.2(MWAR-273),于2012年2月发布
- maven-ear-plugin : 2.8 (MEAR-145), released in Sept. 2012
- maven-ear-plugin:2.8(MEAR-145),于2012年9月发布
- maven-assembly-plugin : 2.4 (MASSEMBLY-634), released in Nov. 2012
- maven-assembly-plugin:2.4(MASSEMBLY-634),于2012年11月发布
- maven-ejb-plugin : 2.4 (MEJB-56), EDIT : released on 24/Aug/14
- maven-ejb-plugin:2.4(MEJB-56),编辑:于24/8月14日发布
- etc.
- 等等
So now we'll have this entry by default in the archive's manifest.mf :
所以现在我们默认在档案的manifest.mf中有这个条目:
Created-By: Apache Maven ${maven.version}
创建者:Apache Maven $ {maven.version}
#3
4
For completeness - this worked for me:
为了完整 - 这对我有用:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.1</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
This puts in my manifest -
这放在我的清单中 -
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: Old.Curmudgeon
Build-Jdk: 1.5.0_22
Implementation-Title: JarFileName-1.0.2
Implementation-Version: 1.0.2
Implementation-Vendor-Id: our.id
#4
2
At least as of version 2.4 of the maven-jar plugin, the following entries are added by default to the MANIFEST.MF file in META-INF in the jar:
至少从maven-jar插件的2.4版本开始,默认情况下将以下条目添加到jar中META-INF中的MANIFEST.MF文件中:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: abcUser
Created-By: Apache Maven 3.3.3
Build-Jdk: 1.8.0_77
To add the project version and other implementation details, simply add the following to the maven-jar-plugin (either in the pluginManagement section or in the build -> plugins section:
要添加项目版本和其他实现细节,只需将以下内容添加到maven-jar-plugin(在pluginManagement部分或build - > plugins部分中:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
To add something like a build time, add the following:
要添加类似构建时间的内容,请添加以下内容:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Build-Time>${maven.build.timestamp}</Build-Time>
</manifestEntries>
</archive>
</configuration>
</plugin>
The Build-Time format can be changed by using the following property in the <properties>
section of your pom.xml:
可以使用pom.xml的
<maven.build.timestamp.format>yyyy-MM-dd HH:mm z</maven.build.timestamp.format>
The output of all the above is something like:
以上所有的输出是这样的:
Manifest-Version: 1.0
Implementation-Title: UI
Implementation-Version: 2.0.5-SNAPSHOT
Archiver-Version: Plexus Archiver
Built-By: abcUser
Implementation-Vendor-Id: com.xyz.abc.dbe
Build-Time: 2016-12-23 12:04 UTC
Created-By: Apache Maven 3.3.3
Build-Jdk: 1.8.0_77
Implementation-Vendor: XYZ Corporation
#5
0
Take a look how it's suggested by jcabi-manifests
: http://manifests.jcabi.com/versioning.html
看看jcabi-manifests是如何建议的:http://manifests.jcabi.com/versioning.html
Also, see this blog post for more details: http://www.yegor256.com/2014/07/03/how-to-read-manifest-mf.html
另外,请参阅此博客文章了解更多详情:http://www.yegor256.com/2014/07/03/how-to-read-manifest-mf.html
#6
0
In order to get the build machine I added the following plugin:
为了获得构建机器,我添加了以下插件:
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>project.properties["hostname"] = InetAddress.getLocalHost().getHostName()</source>
</configuration>
</execution>
</executions>
</plugin>
I could then retrieve the host machine name through ${hostname}.
然后我可以通过$ {hostname}检索主机名。
#1
7
You need to add this plugin:
你需要添加这个插件:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>maven-version</goal>
</goals>
</execution>
</executions>
</plugin>
Check here for details.
点击此处了解详情。
#2
7
We no more need the build-helper-maven-plugin since the feature (MSHARED-38) was added to the component maven-archiver : 2.5 in Feb. 2012 (release notes).
我们不再需要build-helper-maven-plugin,因为该功能(MSHARED-38)已于2012年2月添加到组件maven-archiver:2.5(发行说明)。
And this component is used by the Maven plugins like maven-jar-plugin, maven-war-plugin, maven-ear-plugin, etc.
这个组件被Maven插件使用,如maven-jar-plugin,maven-war-plugin,maven-ear-plugin等。
The versions of these plugins using this feature are :
使用此功能的这些插件的版本是:
- maven-jar-plugin : 2.4 (MJAR-148), released in Feb. 2012
- maven-jar-plugin:2.4(MJAR-148),于2012年2月发布
- maven-war-plugin : 2.2 (MWAR-273), released in Feb. 2012
- maven-war-plugin:2.2(MWAR-273),于2012年2月发布
- maven-ear-plugin : 2.8 (MEAR-145), released in Sept. 2012
- maven-ear-plugin:2.8(MEAR-145),于2012年9月发布
- maven-assembly-plugin : 2.4 (MASSEMBLY-634), released in Nov. 2012
- maven-assembly-plugin:2.4(MASSEMBLY-634),于2012年11月发布
- maven-ejb-plugin : 2.4 (MEJB-56), EDIT : released on 24/Aug/14
- maven-ejb-plugin:2.4(MEJB-56),编辑:于24/8月14日发布
- etc.
- 等等
So now we'll have this entry by default in the archive's manifest.mf :
所以现在我们默认在档案的manifest.mf中有这个条目:
Created-By: Apache Maven ${maven.version}
创建者:Apache Maven $ {maven.version}
#3
4
For completeness - this worked for me:
为了完整 - 这对我有用:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.1</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
This puts in my manifest -
这放在我的清单中 -
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: Old.Curmudgeon
Build-Jdk: 1.5.0_22
Implementation-Title: JarFileName-1.0.2
Implementation-Version: 1.0.2
Implementation-Vendor-Id: our.id
#4
2
At least as of version 2.4 of the maven-jar plugin, the following entries are added by default to the MANIFEST.MF file in META-INF in the jar:
至少从maven-jar插件的2.4版本开始,默认情况下将以下条目添加到jar中META-INF中的MANIFEST.MF文件中:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: abcUser
Created-By: Apache Maven 3.3.3
Build-Jdk: 1.8.0_77
To add the project version and other implementation details, simply add the following to the maven-jar-plugin (either in the pluginManagement section or in the build -> plugins section:
要添加项目版本和其他实现细节,只需将以下内容添加到maven-jar-plugin(在pluginManagement部分或build - > plugins部分中:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
</plugin>
To add something like a build time, add the following:
要添加类似构建时间的内容,请添加以下内容:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Build-Time>${maven.build.timestamp}</Build-Time>
</manifestEntries>
</archive>
</configuration>
</plugin>
The Build-Time format can be changed by using the following property in the <properties>
section of your pom.xml:
可以使用pom.xml的
<maven.build.timestamp.format>yyyy-MM-dd HH:mm z</maven.build.timestamp.format>
The output of all the above is something like:
以上所有的输出是这样的:
Manifest-Version: 1.0
Implementation-Title: UI
Implementation-Version: 2.0.5-SNAPSHOT
Archiver-Version: Plexus Archiver
Built-By: abcUser
Implementation-Vendor-Id: com.xyz.abc.dbe
Build-Time: 2016-12-23 12:04 UTC
Created-By: Apache Maven 3.3.3
Build-Jdk: 1.8.0_77
Implementation-Vendor: XYZ Corporation
#5
0
Take a look how it's suggested by jcabi-manifests
: http://manifests.jcabi.com/versioning.html
看看jcabi-manifests是如何建议的:http://manifests.jcabi.com/versioning.html
Also, see this blog post for more details: http://www.yegor256.com/2014/07/03/how-to-read-manifest-mf.html
另外,请参阅此博客文章了解更多详情:http://www.yegor256.com/2014/07/03/how-to-read-manifest-mf.html
#6
0
In order to get the build machine I added the following plugin:
为了获得构建机器,我添加了以下插件:
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>project.properties["hostname"] = InetAddress.getLocalHost().getHostName()</source>
</configuration>
</execution>
</executions>
</plugin>
I could then retrieve the host machine name through ${hostname}.
然后我可以通过$ {hostname}检索主机名。