【发布时间】:2012-02-01 18:26:23
【问题描述】:
我正在开发一个大型多模块项目,该项目使用内部框架作为其依赖项之一。框架版本在项目开始时在顶级 pom 中设置,并且必须保持不变。如果任何子模块使用不同的版本,我希望构建失败。
我尝试将依赖项声明为单个版本:
<dependency>
<groupId>framework_snt</groupId>
<artifactId>SFP</artifactId>
<version>[6.1]</version>
<type>pom</type>
</dependency>
我尝试过使用具有禁止依赖项的强制插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<id>enforce-versions</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireJavaVersion>
<version>[1.6.0-21]</version>
</requireJavaVersion>
<requireMavenVersion>
<version>[3.0.3]</version>
</requireMavenVersion>
<bannedDependencies>
<excludes>
<exclude>framework_snt:SFP</exclude>
</excludes>
<includes>
<include>framework_snt:SFP:6.1.2</include>
</includes>
</bannedDependencies>
</rules>
</configuration>
</execution>
</executions>
</plugin>
我也尝试添加<DependencyConvergence/> 标签,如here 所述,但这些方法都不起作用。
所以给定这个顶级 pom 片段:
<project>
<groupId>glb</groupId>
<artifactId>GLB</artifactId>
<packaging>pom</packaging>
<name>Global</name>
<version>1.0</version>
........
<dependencies>
<dependency>
<groupId>framework_snt</groupId>
<artifactId>SFP</artifactId>
<version>[6.1.2]</version>
<type>pom</type>
</dependency>
</dependencies>
.....
</project>
还有这个(无效的)子模块:
<project>
<groupId>glb</groupId>
<artifactId>CORE</artifactId>
<packaging>jar</packaging>
<name>Core</name>
<version>1.0</version>
<parent>
<groupId>glb</groupId>
<artifactId>GLB</artifactId>
<version>1.0</version>
</parent>
<dependencies>
<dependency>
<groupId>framework_snt</groupId>
<artifactId>SFP</artifactId>
<version>6.3</version>
<type>pom</type>
</dependency>
</dependencies>
</project>
如何设置 maven,以便在使用上面的子模块时构建会失败,但是当我删除标签 <version>6.3</version> 时它会成功(或者我更改版本以匹配顶级 pom 中的版本?
【问题讨论】:
-
该框架是您公司内部的吗?你能通过nexus设置一个区块吗?
-
是的,该框架是我公司内部的。在 nexus 中设置块不起作用有两个原因:1)我们使用的是 artifactory,2)我需要将这个概念用于不仅仅是内部框架版本。
标签: maven-2 locking dependencies