我正在开发一个在 Eclipse Neon 下导入的 Maven 项目,该项目集成了 M2Eclipse 以及 Maven 的 3.3.9 版本。我的项目的源代码在 SVN 1.6 下管理(是的,我知道它很旧,但我们无法升级到 1.7 或 1.8)。
我想使用该buildnumber-maven-plugin
插件从 svn 存储库中检索修订号并生成增量内部版本号,然后将它们添加到Manifest.MF
.
经过一些试验和错误,pom.xml
下面的内容几乎符合我的预期。事实上,一切都很好,除了 buildNumber 没有随着每次构建顺序增加。例如,每次我在源文件或pom.xml
本身中进行修改时,它都会增加。而且,它并不总是每次都增加 1。我找不到它是如何或何时增加的。
<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>mygroup</groupId>
<artifactId>myartifact</artifactId>
<version>3.1.0</version>
<!-- <packaging>jar</packaging>-->
<name>myproject</name>
<url>http://maven.apache.org</url>
<properties>
<subversion.repository>svn://myserversvn/pse/trunk/</subversion.repository>
<redmine.url>https://myredmine:3000/</redmine.url>
<src>src</src>
<src.java>src/java</src.java>
<src.junit>src/junit</src.junit>
<src.resources>src/resources</src.resources>
<target>target</target>
<target.java>target/java</target.java>
<target.junit>target/junit</target.junit>
<target.javadoc>target/javadoc</target.javadoc>
<compileSource>1.8</compileSource>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Specific properties -->
<codaclibs>${project.basedir}/../dependencies/codac-libs</codaclibs>
</properties>
<scm>
<connection>scm:svn:${subversion.repository}/myproject/trunk</connection>
<developerConnection>scm:svn:${subversion.repository}/myproject</developerConnection>
<url>${redmine.url}/projects/pse/repository</url>
</scm>
<build>
<sourceDirectory>${src.java}</sourceDirectory>
<testSourceDirectory>${src.junit}</testSourceDirectory>
<!-- This section is mandatory to avoid an error message in the definition of buildnumber-maven-plugin -->
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<versionRange>[1.2,)</versionRange>
<goals>
<goal>create</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnConfiguration>true</runOnConfiguration>
<runOnIncremental>true</runOnIncremental>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<!-- First step to get svn revision number as buildNumber -->
<!-- Works only on a machine on which svn is installed (so not on a PC a priori) -->
<execution>
<id>number1</id>
<phase>prepare-package</phase>
<goals>
<goal>create</goal>
</goals>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<revisionOnScmFailure>unknown</revisionOnScmFailure>
<timestampFormat>{0,date,yyyy-MM-dd HH:mm:ss}</timestampFormat>
<getRevisionOnlyOnce>true</getRevisionOnlyOnce>
</configuration>
</execution>
<execution>
<!-- Second step to compute an incremental number as myBuildNumber -->
<id>number2</id>
<phase>prepare-package</phase>
<goals>
<goal>create</goal>
</goals>
<configuration>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<revisionOnScmFailure>svn revision unknown</revisionOnScmFailure>
<buildNumberPropertyName>myBuildNumber</buildNumberPropertyName>
<format>#{0}</format>
<items>
<item>buildNumber</item>
</items>
<timestampFormat>{0,date,yyyy-MM-dd HH:mm:ss}</timestampFormat>
<getRevisionOnlyOnce>true</getRevisionOnlyOnce>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<executions>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
<configuration>
<skip>true</skip>
</configuration>
</execution>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<source>${compileSource}</source>
<target>${compileSource}</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<archive>
<manifest>
<mainClass>${mainclass}</mainClass>
</manifest>
<manifestEntries>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<Build>svn rev ${buildNumber}-build${myBuildNumber} at ${timestamp}</Build>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<forkMode>always</forkMode>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
...
</dependency>
...
</dependencies>
</project>
有人可以告诉我这种行为的原因吗?您知道启动 buildnumber 计算的不同操作吗?有什么想法可以解决这个问题并获得一个“真正的”构建计数器(每次运行“Maven install”命令时增加 1)?
仅供参考,如果我删除检索 svn 修订号( number1 )的执行,这不会影响增量内部版本号的生成。
任何帮助将不胜感激!