Reputation: 375
When writing a custom Gradle plugin, how is it possible to access the extension properties defined per buildtype/flavor in the consuming build.gradle?
I have the following extension class -
TestExtension {
String name;
String address;
// getters and setters
};
Consumer of this gradle plugin would populate properties using closures as shown below -
// default
Test {
address = "default address"
}
android {
buildTypes {
release {
Test {
name = "release-mode"
}
}
}
debug {
Test {
name = "debug-mode"
}
}
}
}
In the gradle plugin, I create and run a separate task for each buildtype. How do you access the right properties when specific task is run? For instance, I never get the right name
property when releasetask is run. its always set to "debug-mode".
Any help is appreciated!
Upvotes: 3
Views: 725
Reputation: 664
inside the apply(Project project){}
-Method of your custom Gradle-Plugin (written in Groovy):
project.android.applicationVariants.all{ variant ->
//do your variant specific code here
}
Upvotes: 1