What's difference between direct dsl and called by a custom function of "apply from:"


(Ronnin Li) #1

First, there are some common scripts deployed in private maven repo:
http://domain/repo/com/d/build/script/java-project/1.0/java-project-1.0.gradle
http://domain/repo/com/d/build/script/maven/1.0/maven-1.0.gradle

In the target project, build.gradle
subprojects {
apply from: 'http://domain/repo/com/d/build/script/java-project/1.0/java-project-1.0.gradle
apply from: ‘http://domain/repo/com/d/build/script/maven/1.0/maven-1.0.gradle
}
it’s OK!
but,
ext.applyScript = { script, version ->
apply from: “http://domain/repo/com/d/build/script/${script}/${version}/${script}-${version}.gradle
}
subprojects {
applyScript(‘java-project’, ‘1.0’)
applyScript(‘maven’, ‘1.0’)
}
it will fail, with message: "Error:Cannot add task ‘:javadocJar’ as a task with that name already exists."
task ‘:javadocJar’ is defined in script 'java-project-1.0.gradle’
and we have several sub projects.

why ?

BTW: can you give me a lead of source location of “apply from:”? It’s hard to location it by myself.