MANIFEST.MF中的buildNumber不是使用buildnumber-maven-plugin和svn生成的

时间:2016-09-19 12:35:59

标签: java maven svn

我正在尝试将内部版本号放在我的EAR的MANIFEST.MF中,基于从SCM检索的版本号(在本例中为svn)。 我有一个带有一些嵌套项目的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包构建项目并查看内部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属性为空。 有什么建议吗?

1 个答案:

答案 0 :(得分:0)

<plugins> tag </plugins>之外创建一个单独的<pluginManagement>,并将buildnumber maven插件分别放在那里。这对我来说是什么,不要问为什么。