Maven项目聚集和变量
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
也许定义一个共同的父母,其中有2个配置文件,为$ {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)
[编辑] 似乎是唯一的技巧自动激活一个配置文件在您的“集合”劲歌,以避免在Maven命令来指定一个属性是
<activation>
<file>
<exists>relative_path_of_file_specific_to_project</exists>
</file>
</activation>
因为基于属性的激活仅适用于系统属性(不是在pom中定义的属性),并且您无法覆盖继承的配置文件配置(默认情况下处于活动状态)。
如果我理解你的问题吧,你希望你的模块有多个家长。这不可能。看到这个discussion。
你可以试试@Gab的建议。基本上定义两个profiles - 一个用于builder-v1,另一个用于builder-v2。您可以在配置文件中执行几乎任何操作,包括指定不同的模块集和不同的属性/版本。
您是否建议为所有模块创建一个具有共同父项的hier,但是需要2个聚合项目? –
这很有帮助,谢谢 我发现一个工作配置: 在常见的父pom中创建2个配置文件并设置属性。按属性激活配置文件。在执行mvn时设置属性:mvn clean package -DsomeProperty = v1 –
>无需在maven命令中指定属性 我们无法在项目pom中使用设置:无法识别的标记:'设置',我们只能激活配置文件maven设置。这不是我想要做的。我尝试conf两个自动构建聚合项目,并通过maven命令激活此工作 –
错过了设置;) – Gab