有什麼辦法來指代從 爲myplugin在我的集結A.gradle聲明的任務?
既然你已經創建項目C,這樣它的包裝插件罐子,可在類路徑中,你可以把在ProjectC/src/main/resources/build-A.gradle
build-A.gradle
。然後,你可以做以下的ProjectC/src/main/groovy/.../MyPlugin.groovy
class MyPlugin implements Plugin<Project> {
void apply(Project project) {
applyFromClasspath(project, 'build-A.gradle')
}
void applyFromClasspath(Project project, String path) {
InputStream in = getClass().classloader.getResourceAsStream(path)
if (in == null) throw new RuntimeException("No such resource $path")
in.withStream { InputStream stream ->
File localFile = project.file("${project.buildDir}/MyPlugin/$path")
localFile.parentFile.mkdirs()
localFile.bytes = stream.bytes
}
project.apply(from: localFile)
}
}
怎麼能得到這樣的配置,螞蟻等,從 的類屬性保持?
這些可從Project實例獲得(例如project.configurations
和project.ant
等)。 Project
對象隱含在build.gradle
文件中,因此configurations
將委託給project.configurations
等。如果您想在插件中使用相同的內容,則可以使用project.with { ... }
。例如:
void apply(Project project) {
project.with {
configurations { ... }
ant.echo(message: 'Hello')
}
}
@see Object.with(Closure)