Gradle/Maven 循环依赖的行为
Behaviour of Gradle/Maven for circular dependencies
我目前正在用我们的 "non-Maven" jar 填充 Maven 存储库,以便 Maven/Gradle 中的未来项目可以使用它们。不幸的是,我们在 "non-Maven" 项目中有一些循环依赖。我现在的问题是,如果 Maven 或 Gradle 遇到
会发生什么
真正的循环依赖,如 foo-1.0.0.jar -> bar-1.0.0-jar -> foo-1.0.0.jar
An "old version circle" 作为 foo-3.0.0.jar 使用 bar-2.0.0.jar 和 bar-2.0.0.jar 使用 foo-1.0 .0.jar.
这不是关于构建 foo.jar 或 bar.jar,而是关于构建依赖于 foo.jar 或 bar.jar 的项目。
真正的循环依赖会导致错误:Maven 会直接构建失败。当您传递依赖与当前项目具有相同 Maven coordinates 的工件时,就会发生循环依赖:groupId
、artifactId
、version
、packaging
和 classifier
。通常,我们处理的 jar
没有分类器,因此具有相同的 groupId
、artifactId
和 version
通常定义循环依赖。
老版本的圆本身并不是圆,因为Maven坐标不一样。在这种情况下,Maven 将通过应用 dependency mediation:
来保留较新的版本
which means that it will use the version of the closest dependency to your project in the tree of dependencies
作为 khmarbaise points out, if you're looking to fail the build even in the case of an old version circle, you can configure the maven-enforcer-plugin
to ban it with the banCircularDependencies
额外规则。
我目前正在用我们的 "non-Maven" jar 填充 Maven 存储库,以便 Maven/Gradle 中的未来项目可以使用它们。不幸的是,我们在 "non-Maven" 项目中有一些循环依赖。我现在的问题是,如果 Maven 或 Gradle 遇到
会发生什么真正的循环依赖,如 foo-1.0.0.jar -> bar-1.0.0-jar -> foo-1.0.0.jar
An "old version circle" 作为 foo-3.0.0.jar 使用 bar-2.0.0.jar 和 bar-2.0.0.jar 使用 foo-1.0 .0.jar.
这不是关于构建 foo.jar 或 bar.jar,而是关于构建依赖于 foo.jar 或 bar.jar 的项目。
真正的循环依赖会导致错误:Maven 会直接构建失败。当您传递依赖与当前项目具有相同 Maven coordinates 的工件时,就会发生循环依赖:groupId
、artifactId
、version
、packaging
和 classifier
。通常,我们处理的 jar
没有分类器,因此具有相同的 groupId
、artifactId
和 version
通常定义循环依赖。
老版本的圆本身并不是圆,因为Maven坐标不一样。在这种情况下,Maven 将通过应用 dependency mediation:
来保留较新的版本which means that it will use the version of the closest dependency to your project in the tree of dependencies
作为 khmarbaise points out, if you're looking to fail the build even in the case of an old version circle, you can configure the maven-enforcer-plugin
to ban it with the banCircularDependencies
额外规则。