伙计们,我的monorepo中有5个项目,我正尝试在他们之间共享任务。我几乎到了我想去的地方,但是在为每个项目设置dirPath变量时遇到了麻烦。以下是artifactUploads.gradle
,其中包含我的customPlugin和一个任务
task copyReleaseBuilds() {
println "test log"
doLast {
//stuff
}.assertNormalExitValue()
}
}
}
}
class UploadPlugin implements Plugin<Project> {
void apply(Project project) {
println "UploadPlugin entry"
//Create container instance for config object
NamedDomainObjectContainer<Config> configContainer =
project.container(Config)
project.extensions.add('uploadConfigs', configContainer)
project.task('uploadTask') << {
def uploadConfig = project.extensions.getByName('uploadConfigs')
println uploadConfig
//Prints DirName
println uploadConfig
uploadConfig.all{
println "{$uploadConfigs.dirPath}"
}
}
}
}
class Config{
String dirPath
Config(String dirPath){
this.dirPath = dirPath
}
}
//uploadConfigs {
// dirPath = ""
//}
每个应用build.gradle
的这一行都为dirPath设置了不同的值
uploadConfigs{
dirPath = "hca/"
}
在尝试构建时,我不断收到此错误
Could not set unknown property 'dirPath' for Config container of type org.gradle.api.internal.FactoryNamedDomainObjectContainer.
我很难理解这一点。当我的Config类还具有一个名称变量(例如
)时,它就可以正常工作class Config{
String name
String dirPath
Config(String name){
this.name = name
}
}
然后分别在每个build.gradle
uploadConfigs{
Nch{
dirPath = "nchmc/"
}
}
这让我感到困惑,我不明白如何为容纳Config类型的容器设置dirPath属性。
谢谢