简体   繁体   中英

How to fix property resolution in multimodule maven build?

I'm transitioning a multi-repository and multi-project build to a single repository multi-module build.

Each project has its own git repo, so when checking out all projects are at the same level.

ProjectA
ProjectB
ProjectC

It is important to note that each project is in a different version. An that ProjectC depends on ProjectB and ProjectB on ProjectA .

I have created an super-pom in a folder at the same level as other projects, and added the other projects as modules in the super-pom and referenced the parent pom in other projects, which results in the following layout:

ProjectX
ModuleA
ModuleB
ModuleC

With child modules having a parent reference as follows:

<parent>
  <groupId>my.company</groupId>
  <artifactId>artifact</artifactId>
  <version>1.0-SNAPSHOT</version>
  <relativePath>../ProjectX</relativePath>
</parent>

I have a settings.xml with two profiles referencing the right snapshot and release versions of each module:

<profile>
  <id>all-snapshot</id>
  <properties>
    <a.version>1.5-SNAPSHOT</a.version>
    <b.version>2.6-SNAPSHOT</b.version>
    <c.version>3.7-SNAPSHOT</c.version>
  </properties>
</profile>
<profile>
  <id>all-release</id>
  <properties>
    <a.version>1.4.0</a.version>
    <b.version>2.5.0</b.version>
    <c.version>3.6.0</c.version>
  </properties>
</profile>

If I issue a project build with mvn clean install -s settings.xml -P all-snapshot -f ProjectX everything seems to work fine and only snapshot dependencies are generated in the local repository. If I execute against the all-release profile it seems to work fine too, downloading only release versions to the local maven repository.

But if I try to build a single modudle mvn clean install -s settings.xml -P all-snapshot -f ProjectX -pl :modulec , I get:

Could not resolve dependencies for project modulec:3.7-SNAPSHOT: The following artifacts could not be resolved: moduleb:jar:${b.version}, moduela:jar:${a.version}

Looks like property resolution is not working fine, either because the maven invocation is missing something or because the project layout is hurting maven.

Any ideas on how to fix this? Or a better approach to merging the repos into a single build?

I'm transitioning a multi-repository and multi-project build to a single repository multi-module build.

[...]

It is important to note that each project is in a different version.

If you want to have different versions for different projects, I strongly recommend to keep them in different repositories as otherwise you will end-up in all sorts of tooling issues.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM