简体   繁体   English

如何修复多模块Maven构建中的属性解析?

[英]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. 每个项目都有自己的git repo,因此在签出所有项目时都处于同一级别。

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 . ProjectC依赖于ProjectBProjectB依赖于ProjectA An。

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: 我已经在与其他项目相同级别的文件夹中创建了一个超级pom,并将其他项目作为模块添加到超级pom中,并在其他项目中引用了父pom,这导致了以下布局:

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: 我有一个settings.xml其中包含两个配置文件,引用了每个模块的正确快照和发行版:

<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. 如果我使用mvn clean install -s settings.xml -P all-snapshot -f ProjectX发布项目构建,那么一切似乎都可以正常工作,并且本地存储库中仅生成了快照依赖项。 If I execute against the all-release profile it seems to work fine too, downloading only release versions to the local maven repository. 如果我对all-release配置文件执行它似乎也可以正常工作,仅将发布版本下载到本地maven存储库。

But if I try to build a single modudle mvn clean install -s settings.xml -P all-snapshot -f ProjectX -pl :modulec , I get: 但是,如果我尝试构建单个模块mvn clean install -s settings.xml -P all-snapshot -f ProjectX -pl :modulec全新mvn clean install -s settings.xml -P all-snapshot -f ProjectX -pl :modulecmvn clean install -s settings.xml -P all-snapshot -f ProjectX -pl :modulec得到:

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. 看起来属性解析不能正常工作,这可能是因为Maven调用缺少了某些东西,或者是因为项目布局损害了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. 如果要为不同的项目使用不同的版本,强烈建议将它们保留在不同的存储库中,否则您将面临各种工具问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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