我正在尝试使用Gradle Composite Builds在我的解决方案中构建多个独立项目。从Composite构建构建时,任何覆盖resolutionStrategy
的插件似乎都会被忽略。
项目布局
| master <<Composite Build>>
| |\ -- settings.gradle
| | -- build.gradle
| library1
| |\ -- settings.gradle
| | -- build.gradle
| library2
| |\ -- settings.gradle
| | -- build.gradle
| mulitProj << Multi Project>>
| |\ -- settings.gradle
| | -- build.gradle
| - multiProjChild1
| | |\ -- build.gradle
| - multiProjChild2
| | |\ -- build.gradle
复合构建(主):
settings.gradle
===============
includeBuild('../library1') {
dependencySubstitution {
substitute module('com.company:library1') with project (':')
}
}
includeBuild('../library2') {
dependencySubstitution {
substitute module('com.company:library2') with project (':')
}
}
includeBuild('../multiProj')
构建(library1,library2,multiProject):
请注意,所有build.gradle
个文件都使用Spring依赖关系管理来共享公共库版本。
build.gradle
============
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
classpath(
'io.spring.gradle:dependency-management-plugin:0.6.1.RELEASE'
)
}
}
allprojects {
apply plugin: "io.spring.dependency-management"
dependencyManagement {
dependencies {
dependency 'com.fasterxml.jackson.core:jackson-core:2.6.3'
dependency 'com.fasterxml.jackson.core:jackson-annotations:2.6.3'
...
}
}
}
...
dependencies {
compile(
'com.fasterxml.jackson.core:jackson-core',
'com.fasterxml.jackson.core:annotations',
...
当我单独构建任何项目(library1,library2,multiProj)时,它们构建正常。
当我构建Composite构建master
时,多项目忽略dependencyManagement
提供的依赖关系解析自定义。
我已经编写了自己的Gradle插件,看看我是否可以重现这个。事实证明,在复合构建中构建多项目构建时,永远不会调用Closure
中的resolutionStrategy.eachDependency
。
例如:
/** Gradle plugin to resolve dependencies **/
class DependencyResolverPlugin implements Plugin<Project> {
@Override
public void apply(Project project) {
project.configurations.all {
// Resolve managed dependency versions
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
// !!
// This Closure is never called when this plugin is
// applied to a multi project build, which is built
// in a composite build
// !!
if (details.requested.version == null) {
//Replace the version with the managed dependency version
}
}
}
}
}
我希望解决方案策略定制在与Composite Build一起使用时继续工作。