1
我正嘗試使用Gradle Composite Builds在我的解決方案中構建多個獨立項目。覆蓋resolutionStrategy
的任何插件在從Composite構建時似乎都會被忽略。Gradle 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,多項目):
注意,所有build.gradle
文件正在使用spr依賴關係管理共享通用庫版本。
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插件,看看我是否可以重現這一點。事實證明,在複合構建中構建多項目構建時,永遠不會調用resolutionStrategy.eachDependency
中的Closure
。
例如:
/** 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
}
}
}
}
}
我想解決策略的定製,以繼續進行綜合編譯時工作。