Agregate項目1:Maven項目聚集和變量
<groupId>com.mycompany</groupId>
<artifactId>builder</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<modules>
<module>../module-1</module>
<module>../module-2</module>
</modules>
<properties>
<project.parent.pom>../builder-v1/pom.xml</project.parent.pom>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<lib.version>2.5.1</lib.version>
</properties>
Agregate項目2:
<groupId>com.mycompany</groupId>
<artifactId>builder</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<modules>
<module>../module-1</module>
<module>../module-4</module>
<module>../module-6</module>
</modules>
<properties>
<project.parent.pom>../builder-v2/pom.xml</project.parent.pom>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<lib.version>2.6.0</lib.version>
</properties>
模塊1:
<parent>
<groupId>com.mycompany</groupId>
<artifactId>builder</artifactId>
<version>1.0.0</version>
<relativePath>../builder-v1/pom.xml</relativePath>
<!--<relativePath>${project.parent.pom}</relativePath> not work-->
</parent>
<groupId>com.mycompany</groupId>
<artifactId>module-1</artifactId>
節relativePath與骨料POM可變不起作用
<relativePath>../builder-v1/pom.xml</relativePath>
<!--<relativePath>${project.parent.pom}</relativePath> not work-->
但我需要diffrent $ {lib.version}在聚合項目。如果我從 模塊1刪除繼承部分:
<!--<parent>
<groupId>com.mycompany</groupId>
<artifactId>builder</artifactId>
<version>1.0.0</version>
<relativePath>../builder-v1/pom.xml</relativePath>
</parent>-->
<groupId>com.mycompany</groupId>
<artifactId>module-1</artifactId>
變量不傳遞給子模塊和我得到的錯誤:
'dependencies.dependency.version' for com.somelib:some-lib:jar must be a valid version but is '${lib.version}'.
如何配置骨料項目和轉讓變量放入模塊?
UPDATE與@Gab評論
父POM:
<groupId>com.mycompany</groupId>
<artifactId>parent</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<profiles>
<profile>
<id>v1</id>
<activation>
<property>
<name>project.type</name>
<value>v1</value>
</property>
</activation>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<lib.version>2.5.1</lib.version>
</properties>
</profile>
...
</profiles>
模塊1:
<parent>
<groupId>com.mycompany</groupId>
<artifactId>parent</artifactId>
<version>1.0.0</version>
</parent>
<groupId>com.mycompany</groupId>
<artifactId>module-1</artifactId>
Agregate項目1:
<groupId>com.mycompany</groupId>
<artifactId>builder-v1</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<modules>
<module>../module-1</module>
<module>../module-2</module>
</modules>
當執行建設者-V1的目標啓動配置文件project.type = V1:
mvn clean package --file=pom_v1.xml -Dproject.type=v1 -Dproject.main.module=module-1
這很有幫助,謝謝 我發現一個工作配置: 在常見的父pom中創建2個配置文件並設置屬性。按屬性激活配置文件。在執行mvn時設置屬性:mvn clean package -DsomeProperty = v1 –
>無需在maven命令中指定屬性 我們無法在項目pom中使用設置:無法識別的標記:'設置',我們只能激活配置文件maven設置。這不是我想要做的。我嘗試conf兩個自動構建聚合項目,並通過maven命令激活此工作 –
錯過了設置;) – Gab