【发布时间】:2013-03-29 00:03:04
【问题描述】:
我有一个问题,不知道是否有人可以帮助我解决。 我的项目中有一个模块结构,我使用 Maven 解决依赖关系。对于这个结构,我有不同内容的版本,我使用分类器来区分。对于每个分类器,我在父 pom 中定义了一个配置文件,其中包含属性中分类器的字符串。这样,在我的模块中,我使用了这个属性,并且是我定义的配置文件,谁决定了分类器常量。 我现在遇到的问题是,当依赖关系是从我在我的一个模块的 pom 中定义的依赖关系继承时,依赖层次结构无法识别分类器。 例如,如果我有项目 A、B 和 C,B 依赖于 A,C 依赖于 B,从 C 中我得到 B 和分类器,而不是 A。 如果我使用父 pom 中的属性,就会发生这种情况。如果我直接使用常量字符串,则依赖项会被正确捕获。 我看到的唯一解决方案是在每个 pom 上使用配置文件来定义它们内部的依赖关系。但我有 5 个配置文件!难道没有其他方法可以解决这个问题吗? 我正在使用带有 m2e 插件的 STS 3.8 作为我的 IDE。
提前谢谢你!
我添加了 poms
父pom:
<profiles>
<profile>
<id>TRUNK</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<svnBranch />
</properties>
</profile>
<profile>
<id>MON</id>
<properties>
<svnBranch>MON</svnBranch>
</properties>
</profile>
<profile>
<id>LOLA</id>
<properties>
<svnBranch>LOLA</svnBranch>
</properties>
</profile>
<profile>
<id>NBA</id>
<properties>
<svnBranch>NBA</svnBranch>
</properties>
</profile>
<profile>
<id>TEST</id>
<properties>
<svnBranch>TEST</svnBranch>
</properties>
</profile>
<profile>
<id>PROD</id>
<properties>
<svnBranch>PROD</svnBranch>
</properties>
</profile>
</profiles>
项目A:
<parent>
<groupId>com.myproject</groupId>
<artifactId>pom</artifactId>
<version>1.0.10</version>
</parent>
<artifactId>core-services</artifactId>
<version>1.1.0.41-SNAPSHOT</version>
项目 B:
<parent>
<groupId>com.mycompany</groupId>
<artifactId>pom</artifactId>
<version>1.0.10</version>
</parent>
<artifactId>olb-services</artifactId>
<version>1.1.0.41-SNAPSHOT</version>
<properties>
<module.core-services.dependency.version>1.1.0.41-SNAPSHOT</module.core-services.dependency.version>
</properties>
<dependencies>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>core-services</artifactId>
<version>${module.core-services.dependency.version}</version>
<classifier>${svnBranch}</classifier>
</dependency>
</dependencies>
项目 C:
<parent>
<groupId>com.mycompany</groupId>
<artifactId>pom</artifactId>
<version>1.0.10</version>
</parent>
<artifactId>nba-services</artifactId>
<version>1.1.0.41-SNAPSHOT</version>
<properties>
<module.olb-services.dependency.version>1.1.0.41-SNAPSHOT</module.olb-services.dependency.version>
<module.core-services.dependency.version>1.1.0.41-SNAPSHOT</module.core-services.dependency.version>
</properties>
<dependencies>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>olb-services</artifactId>
<version>${module.olb-services.dependency.version}</version>
<classifier>${svnBranch}</classifier>
</dependency>
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>core-services</artifactId>
<version>${module.core-services.dependency.version}</version>
<classifier>${svnBranch}</classifier>
</dependency>
</dependencies>
在每个依赖项的分类器标记中使用 ${svnBranch} 不起作用。看起来在项目 B 中,当项目 C 引用时,属性 ${svnBranch} 是空的,但它来自父 pom。
【问题讨论】:
-
请提供您的示例 pom.xml
-
默认情况下(TRUNK 配置文件)你的
属性是空的,所以对于孩子来说它是空的似乎是正确的 -
当使用
mvn ... -DsvnBranch=...显示名为svnBranch的system properties时,配置文件将处于活动状态。请使用以下命令提供有效的pom结果mvn help:effective-pom -DsvnBranch=... -
还是不行。我试过改变属性,但它不是继承的。使用
mvn help:effective-pom我没有得到整个依赖树,但是如果我运行这个命令mvn clean install -P MON -DsvnBranch=MON -X我得到这个[DEBUG] com.mycompany:olb-web:jar:1.1.0.41-SNAPSHOT [DEBUG] com.mycompany:core-web:jar:MON:1.1.0.41-SNAPSHOT:compile [DEBUG] com.mycompany:core-services:jar:1.1.0.41-SNAPSHOT:compile。第一个依赖项使用我的分类器,但继承的没有。我想我唯一的选择是为每个分支使用不同的属性。