问题
Agregate Project 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 Project 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>
Module 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>
Section relativePath with variable from aggregate pom not work
<relativePath>../builder-v1/pom.xml</relativePath>
<!--<relativePath>${project.parent.pom}</relativePath> not work-->
But I need diffrent ${lib.version} in aggregate projects. If I delete inheritance part from Module 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>
Variables are not passed to the child modules and i got error:
'dependencies.dependency.version' for com.somelib:some-lib:jar must be a valid version but is '${lib.version}'.
How can I configure aggregate project and transfer variables into modules?
UPDATE with @Gab comments
Parent 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>
Module 1:
<parent>
<groupId>com.mycompany</groupId>
<artifactId>parent</artifactId>
<version>1.0.0</version>
</parent>
<groupId>com.mycompany</groupId>
<artifactId>module-1</artifactId>
Agregate Project 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>
When execute builder-v1 goals activate profile project.type=v1:
mvn clean package --file=pom_v1.xml -Dproject.type=v1 -Dproject.main.module=module-1
回答1:
maybe define a common parent with 2 profile defining different values for ${lib.version} and automatically activate one profile in your "aggregates" poms. All your module will inherit from the parent one
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)
[edit] Seems the only trick to automatically activate one profile in your "aggregates" poms to avoid to specify a property in the maven command is
<activation>
<file>
<exists>relative_path_of_file_specific_to_project</exists>
</file>
</activation>
because the property based activation works only with system properties (not the one defined in pom) and you can't override inherited profile configuration (active by default).
回答2:
If I understand your question right, you want your module to have multiple parents. This is not possible. See this discussion.
You could try suggestion of @Gab. Essentially define two profiles - one for builder-v1 and another for builder-v2. You can do pretty much anything inside a profile, including specifying different set of modules and different properties/versions.
来源:https://stackoverflow.com/questions/22346109/maven-project-aggregation-and-variables