Access property from settings.gradle in Gradle plugin
Apparently, the way to go (which is better anyways) is to use an extension object. This extension object allows to send data from the build.gradle
file to the plugin. The build.gradle
file reads the content of the variable in the settings.gradle
file and puts it in the extension object.
In the file containing the plugin:
package myplugin.gradle
import org.gradle.api.Project
import org.gradle.api.Plugin
class MyExtension {
String myProperty
}
class FirstPlugin implements Plugin<Project> {
void apply(Project project) {
project.extensions.create('myExtensionName', MyExtension)
project.task('myTask') << {
def instance = project.myExtensionName.myProperty
println "VALUE : " + instance
}
}
}
In the build.gradle
file:
apply plugin: 'myPluginName'
...
myExtensionName {
myProperty = gradle.ext.myPropertyInSettings
}
And finally, in the settings.gradle
file :
gradle.ext.myPropertyInSettings = "The Value"
Also, I recommend this tutorial instead of the one provided by Gradle.