![](/img/trans.png)
[英]maven-release-plugin in multi-module project having a seperate git repository for each module
[英]maven-release-plugin does not work for multi-module POMs
插件版本: 2.0
我正在嘗試使用maven-release-plugin來設置父POM和所有模塊的版本。
使用以下父POM:
<?xml version="1.0" encoding="UTF-8"?>
<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>uk.co.mycompany</groupId>
<artifactId>myProject</artifactId>
<version>latest-SNAPSHOT</version>
<packaging>pom</packaging>
<name>My Project</name>
<modules>
<module>../../subPom1</module>
<module>../../subPom2</module>
<module>../../subPom3</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<phase>clean</phase>
<id>set-release-versions</id>
<configuration>
<developmentVersion>1.1.8</developmentVersion>
<autoVersionSubmodules>true</autoVersionSubmodules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
運行mvn clean install -DskipTests -Pdeploy
,將完全忽略在clean階段運行插件的配置,並使用值“latest-SNAPSHOT”進行構建。
我期待它從插件配置中獲取值“1.1.8”。
每個孩子POM相當於:
<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>
<parent>
<groupId>uk.co.mycompany</groupId>
<artifactId>myProject</artifactId>
<version>latest-SNAPSHOT</version>
<relativePath>../../System/build/parentPom.xml</relativePath>
</parent>
...
</project>
為什么忽略配置?
按要求編輯#1:文件系統結構:
/
|- system
| |
| |- build
| |
| |-parentPOM file
|
|- business
| |
| | - childPOM1
| | - childPOM2
|- client
| | - childPOM3
| | - childPOM4
忽略SSCCE中的...... / ... - 我已經模糊了真正的值來描述這個問題。
編輯#2:我已按照建議將定義移至<pluginManagement>
,但問題仍然相同(不使用插件,沒有反饋到控制台):
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.0</version>
<configuration>
<developmentVersion>1.1.8</developmentVersion>
<autoVersionSubmodules>true</autoVersionSubmodules>
</configuration>
</plugin>
</plugins>
</pluginManagement>
你忘了設置插件的目標。 您配置了更新版本目標所需的參數,但您告訴maven只在清潔階段執行插件,而不是插件的目標。 所以它什么都不做。
當你嘗試mvn clean時檢查maven日志它應該只顯示:
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ test ---
當您將配置更改為:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<phase>clean</phase>
<id>set-release-versions</id>
<goals><goal>update-versions</goal></goals>
<configuration>
<developmentVersion>1.1.8</developmentVersion>
<autoVersionSubmodules>true</autoVersionSubmodules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
目標更新版本在maven的清潔階段調用。
[INFO] --- maven-release-plugin:2.0:update-versions (set-release-versions) @ bdd ---
不確定這是否會解決您的所有問題,但這將迫使maven在清潔階段執行插件,如預期的那樣。
但是,當用於僅更改版本時,發布插件需要許多特殊設置(如scm連接)。 所以我建議使用versions-maven-plugin
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<goals>
<goal>set</goal>
</goals>
<phase>clean</phase>
<configuration>
<newVersion>1.1.8</newVersion>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
最后,我放棄了。
Stack Overflow等所有這些問題都充滿了未解決的問題,並且插件文檔無法提供POM格式的使用示例,告訴我關於此插件需要了解的所有內容。
我的解決方法是將父POM的版本設置為“latest-SNAPSHOT”並引入一個名為<myproject.release.version>,
的屬性<myproject.release.version>,
我在任何地方都使用它來打印版本號。
特別是,我想在WAR文件的清單中打印版本號。 我這樣做如下:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestEntries>
<Implementation-Version>${myproject.release.version}</Implementation-Version>
</manifestEntries>
</archive>
</configuration>
<executions>
<execution>
<id>war</id>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
<configuration>
<filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
<filters>
<filter>${project.parent.basedir}/filter/${webapp.filter}.properties</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
使用上面的配置,我將版本號作為Maven屬性刪除到我的清單中。
在我的應用程序中,我從那里拿起它並在屏幕上繪制它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.