Agregate项目1:
<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>来自聚合pom的变量的节relativePath不工作
<relativePath>../builder-v1/pom.xml</relativePath>
<!--<relativePath>${project.parent.pom}</relativePath> not work-->但在总体项目中我需要不同的${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}'.如何配置聚合项目并将变量转换为模块?
带有@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>当执行builder-v1目标时,激活配置文件project.type=v1
mvn clean package --file=pom_v1.xml -Dproject.type=v1 -Dproject.main.module=module-1发布于 2014-03-12 11:09:27
可以用两个配置文件定义${lib.version}的不同值,并自动激活“聚合”poms中的一个配置文件。所有模块都将从父模块继承。
parent-pom (defining 2 different profiles)
|
+ aggregate 1 (inherit from parent-pom - activate profile 1)
| |
| + module 1 (inherit from parent-pom)
|
| + module 2 (inherit from parent-pom)
+ aggregate 2 (inherit from parent-pom - activate profile 2)
|
+ module 1 (inherit from parent-pom)
|
+ module 3 (inherit from parent-pom)编辑似乎是在“聚合”poms中自动激活一个配置文件以避免在maven命令中指定属性的唯一技巧。
<activation>
<file>
<exists>relative_path_of_file_specific_to_project</exists>
</file>
</activation>因为基于属性的激活只适用于系统属性(而不是pom中定义的属性),因此不能覆盖继承的配置文件配置(默认情况下是活动的)。
发布于 2014-03-12 10:02:26
如果我正确理解你的问题,你希望你的模块有多个父母。这是不可能的看这个讨论。
你可以试试@Gab的建议。本质上定义了两个配置文件 -一个用于构建器-v1,另一个用于构建器-v2。您几乎可以在配置文件中执行任何操作,包括指定不同的模块集和不同的属性/版本。
https://stackoverflow.com/questions/22346109
复制相似问题