buildscript {
project.ext.gradle_plugin_path = '/the/gradle/plugin/path'
apply from: "${project.ext.gradle_plugin_path }/etc/buildinfra/buildscript.gradle", to: buildscript
apply plugin: "plugin-provided-by-me''
The thing is the project.ext.gradle_plugin_path is also used in the implementation of my plugins, which requires user to do exactly above to define a variable named project.ext.gradle_plugin_path first ,and then apply the buildscript.gradle.
What I want to achieve is user only need to: buildscript {
apply from: “/the/gradle/plugin/path/etc/buildinfra/buildscript.gradle”, to: buildscript }
And inside the implementation of my buildscript.gradle, I could parse and store the value of gradle_plugin_path, which could be used late in my plugins - thus reduce the burden from our users.
But, it seems neither project nor rootProect is accessible from within buildscript.gradle, with an error like: > * What went wrong: > A problem occurred evaluating script. > > No such property: rootProject for class: org.gradle.api.internal.initialization.DefaultScriptHandler
How should I acheive this? it is not necessary to be rootProject, any global accessible variable that I can save the value and then retrieved would be fine. (I would only use systemproperties or environment variables as a last resort )
Thanks very much.
Change this:
apply from: “${project.ext.gradle_plugin_path }/etc/buildinfra/buildscript.gradle”, to: buildscript
apply from: “${project.ext.gradle_plugin_path }/etc/buildinfra/buildscript.gradle”, to: project
Then you’ll have to wrap your buildscript.gradle content in ‘buildscript {}’.
That’s the only way to get access to the project object in your external script.