Gradle:将配置foo定义如下:
task fooJar(type: Jar) {
...
}
configurations {
foo.extendsFrom("compile")
}
artifacts {
foo fooJar
}
如果配置名称是变量,如何写?例如,
['foo', 'bar'].each {
task "${it}Jar"(type: Jar) {
....
}
configurations {
"$it".extendsFrom("compile")
}
artifacts {
"$it" tasks["${it}Jar"]
}
}
第二部分:添加神器:
artifacts.add(config, tasks["${it}Jar"])
错误:
> Could not find method add() for arguments [configuration 'foo', task
'fooJar'] on object of type
org.gradle.api.internal.artifacts.dsl.DefaultArtifactHandler.
答案 0 :(得分:1)
例如
Configuration config = configurations.create(it)
config.extendsFrom configurations.getByName('xxx')