jav*_*irl 1 build-automation release-management maven
假设我有一个pom文件,
<version>14.4.1-SNAPSHOT</version>
Run Code Online (Sandbox Code Playgroud)
它定义了要构建的项目的版本.该值由我们的构建系统(jenkins)自动更新.
稍后,在其中一个插件中,我需要一个属性,其中包含版本中的前两个数字,因此对于14.4.1-SNAPSHOT值,它将是"14.4",并且对于13.12.39-SNAPSHOT价值将是"13.12".
目前,我们每月手动更新此值:
<plugins>
<plugin>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-maven-plugin</artifactId>
<version>2.0.1</version>
<executions>
<execution>
<id>default-cli</id>
<phase>process-resources</phase>
<configuration>
<changeLogFile>src/main/resources/14.4/changeLog.xml</changeLogFile>
Run Code Online (Sandbox Code Playgroud)
理想情况下,我希望有类似的东西
<changeLogFile>src/main/resources/${releaseVersion}/changeLog.xml</changeLogFile>
Run Code Online (Sandbox Code Playgroud)
但是如何${releaseVersion}自动计算出这个(= 14.4)<version>14.4.1-SNAPSHOT</version>?
在这种情况下,它绝对是自动化的,我们没有任何手动流程.是否有任何表达式 - 我可以在pom文件中使用哪种语言,它可以解析字符串 14.4.1-SNAPSHOT并从中生成一个14.4?
您可以使用parse-version尝试mojo build-helper.
[编辑]这是我的例子pom.xml:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<webResources>
<resource>
<filtering>true</filtering>
<targetPath>WEB-INF</targetPath>
<directory>src/main/resources/${parsedVersion.majorVersion}.${parsedVersion.minorVersion}</directory>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>validate</phase>
<id>parse-version</id>
<goals>
<goal>parse-version</goal>
</goals>
<configuration>
<propertyPrefix>parsedVersion</propertyPrefix>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<echo>Major: ${parsedVersion.majorVersion}</echo>
<echo>Minor: ${parsedVersion.minorVersion}</echo>
<echo>Incremental: ${parsedVersion.incrementalVersion}</echo>
<echo>Qualifier: ${parsedVersion.qualifier}</echo>
<echo>BuildNumber: ${parsedVersion.buildNumber}</echo>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
780 次 |
| 最近记录: |