Gradle attempts to reuse classloaders between build invocations to keep classes "hot" (since Gradle 2.4). This has implications for how Gradle plugins (and their dependencies) are written. Specifically, Gradle plugins, tasks, extensions, etc should in general not keep static state because it can cause problems like resource leaks and make it seem like configuration changes are being ignored.
This leads to other bad advice like:
- Don't use the daemon at all
- Delete your GRADLE_USER_HOME
- Stop/restart the daemon when changing configuration
This would be appropriate in our Gradle guides on plugin development and/or the user manual.
Context
Given a plugin like this:
class MyPlugin implements Plugin<Project> {
static String prop = System.getProperty("myproperty", "default")
void apply(Project project) {
project.logger.lifecycle("myproperty is " + prop)
}
}
apply plugin: MyPlugin
When you run gradle help, this produces the message "myproperty is default".
When you run gradle help -Dmyproperty=somethingelse, this produces the message "myproperty is default". (surprising!)
When you then stop the daemon and run gradle help -Dmyproperty=somethingelse, this produces the message "myproperty is somethingelse". This is the message you'll get until you stop the daemon/use another daemon.
Gradle attempts to reuse classloaders between build invocations to keep classes "hot" (since Gradle 2.4). This has implications for how Gradle plugins (and their dependencies) are written. Specifically, Gradle plugins, tasks, extensions, etc should in general not keep static state because it can cause problems like resource leaks and make it seem like configuration changes are being ignored.
This leads to other bad advice like:
This would be appropriate in our Gradle guides on plugin development and/or the user manual.
Context
Given a plugin like this:
When you run
gradle help, this produces the message "myproperty is default".When you run
gradle help -Dmyproperty=somethingelse, this produces the message "myproperty is default". (surprising!)When you then stop the daemon and run
gradle help -Dmyproperty=somethingelse, this produces the message "myproperty is somethingelse". This is the message you'll get until you stop the daemon/use another daemon.