java - 在多模块项目中覆盖配置文件中的属性在 Maven 中无法正常工作
问题描述
Pom A 是 Pom B 和 Pom C 的父级。
Pom A 有一个配置文件 sample-profile,它覆盖了 Pom A 中定义的属性 <scala.version>。
<scala.version> 的默认值为 ,为此属性2.11
定义的值为2.12。sample-profile
在 Pom A 的 dependencyManagement 部分中,一个依赖项的 artifactId 取决于 <scala.version> 的值。
<dependency>
<groupId>com.github.scopt</groupId>
<artifactId>scopt_${scala.version}</artifactId>
<version>3.7.0</version>
</dependency>
项目 C 依赖于 scopt_${scala.version}。项目 B 依赖于项目 C。
期望的行为是:
- 运行
mvn clean install -DskipTests -Psample-profile
并获取项目 C 取决于 scopt_2.12。
实际行为是:
当我运行mvn clean install -DskipTests -Psample-profile
或mvn dependency:tree -Psample-profile
在 Project B 的目录中时, Project C 的 artifactIdscopt_2.11
不是scopt_2.12
mvn help:effective-pom -Psample-profile
虽然没有产生 scopt_2.11 的痕迹。
我该如何解决这个问题?
[编辑] - 最初,我使用示例配置文件从 Pom A 构建所有内容(当我这样做时,我有所需的行为,即将 scopt_2.12 作为项目 C 的依赖项)。然后在对项目 B 进行代码修改后,我只需要从 Pom B 构建(具有相同的示例配置文件)。这就是我出现意外行为的时候(即,将 scopt_2.11 作为项目 C 的依赖项)。
解决方案
我不确定真正的原因,但 maven 可能会在解析配置文件之前尝试解决依赖关系。特别是因为它们可能会影响插件,这可能会扩展 maven(请参阅maven 扩展)。
你可以试试这个:
- 在你的 中声明这两个版本
dependencyManagement
,没有任何配置文件 jinx。 - 在子项目 (B) 中,
<artifactId>scopt_${scala.version}</artifactId>
用作 artifactId。
这可能有效。
推荐阅读
- angular - Angular如何将数组传递给组件
- amazon-web-services - 是否有任何 API 来获取 AWS 检查员的调查结果数据
- python - 我们可以将我们的 Flask 应用程序直接连接到 Nginx 服务器吗?
- java - 从pdf文件中提取具有文本的文本和图像
- vue.js - 未配置 Visual Studio Code 自动格式化程序
- javascript - 使用 webdriver.io 模块获取当前 URL
- amazon-web-services - DynamoDB - 创建表 - IAM 策略 - 未授权错误
- java - HttpsURLConnection 提供连接超时,但使用 JS XMLHttpRequest()
- naming-conventions - 验证用户或验证电话号码?哪个更有意义、更好和更标准?为什么?
- java - 处理按钮区域中手指的进出