【发布时间】:2016-09-19 12:35:59
【问题描述】:
我正在尝试根据从 SCM 检索到的修订号(在本例中为 svn)将内部版本号放入我的 EAR 的 MANIFEST.MF。 我有一个带有一些嵌套项目的 Maven 父项目,其中一个负责创建 EAR。
这是我的父 pom.xml:
<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>com.example</groupId>
<artifactId>app</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<sourceVersion>1.8</sourceVersion>
<targetVersion>1.8</targetVersion>
</properties>
<scm>
<connection>scm:svn:svn://name.surname@serverName/example/branches/tryRevision</connection>
</scm>
<modules>
...
<module>app-ear</module>
</modules>
<build>
<!-- plugins used by this POM and all inheriting POMs -->
<pluginManagement>
<plugins>
<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>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<revisionOnScmFailure>no-revision</revisionOnScmFailure>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<version>1.9.5</version>
<configuration>
<connectionType>connection</connectionType>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
这是 app-ear/pom.xml:
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<parent>
<groupId>com.example</groupId>
<artifactId>app</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>app-ear</artifactId>
<packaging>ear</packaging>
<build>
<finalName>${project.artifactId}-${project.version}</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>${sourceVersion}</source>
<target>${targetVersion}</target>
<verbose>true</verbose>
<fork>true</fork>
<executable>${compilerLocation}</executable>
</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>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<revisionOnScmFailure>no-revision</revisionOnScmFailure>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10.1</version>
<configuration>
<skinnyWars>true</skinnyWars>
<finalName>myapp</finalName>
<version>7</version>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<archive>
<manifestEntries>
<SCM-Revision>${buildNumber}</SCM-Revision>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
...
</dependencies>
</project>
我使用 mvn clean package 构建项目并查看耳朵 META-INF/MANIFEST.MF 我明白了:
Manifest-Version: 1.0
SCM-Revision:
Archiver-Version: Plexus Archiver
Built-By: me
Created-By: Apache Maven 3.3.9
Build-Jdk: 1.8.0_102
如您所见,buildnumber-maven-plugin 中的 buildNumber 属性为空。 有什么建议吗?
【问题讨论】:
-
您需要执行 buildnumber-maven-plugin 但您只在 pluginManagement 中定义了它。所以没有绑定到生命周期。
-
我已经更改了 app-ear/pom.xml,包括 buildnumber-maven-plugin。 MANIFEST.MF 中没有任何变化
-
请将示例项目放在github上,我可以看看...
-
这里是github.com/chess4ever/maven-buildnumber-plugin,要运行它你必须设置JAVA_HOME环境变量