Build failure with 2.4 (works fine with 2.3)

A problem occurred evaluating root project 'XXX'.
> Failed to apply plugin [class 'org.gradle.language.base.plugins.LifecycleBasePlugin']
     > Cannot create 'tasks.clean' using creation rule 'tasks.addPlaceholderAction(clean)' as model element 'tasks' is no longer mutable.

I can’t reproduce the issue in small project. Stacktrace points to an applied script file where I apply java plugin.

I have no idea what that error means, I’m not even touching or creating any tasks which would collide with lifecycle tasks.

The whole thing works like this (simplified version):
Init script:

rootProject.allProjects {
    apply from: 'myscript.gradle' 
}

build script:

project(':my-project') {
    useJava()
}

myscript.gradle:

ext.useJava = {  configure(project) { apply plugin: 'java' }  }

Stacktrace doesn’t show anything interesting:

Caused by: java.lang.IllegalStateException: Cannot create ‘tasks.clean’ using creation rule ‘tasks.addPlaceholderAction(clean)’ as model element ‘tasks’ is no longer mutable.
at org.gradle.model.internal.registry.DefaultModelRegistry.registerNode(DefaultModelRegistry.java:123)
at org.gradle.model.internal.registry.DefaultModelRegistry.access$500(DefaultModelRegistry.java:49)
at org.gradle.model.internal.registry.DefaultModelRegistry$ModelElementNode.addLink(DefaultModelRegistry.java:991)
at org.gradle.api.internal.tasks.DefaultTaskContainer.addPlaceholderModelLink(DefaultTaskContainer.java:247)
at org.gradle.api.internal.tasks.DefaultTaskContainer.addPlaceholderAction(DefaultTaskContainer.java:239)
at org.gradle.language.base.plugins.LifecycleBasePlugin.addClean(LifecycleBasePlugin.java:56)
at org.gradle.language.base.plugins.LifecycleBasePlugin.apply(LifecycleBasePlugin.java:47)
at org.gradle.language.base.plugins.LifecycleBasePlugin.apply(LifecycleBasePlugin.java:34)
at org.gradle.api.internal.plugins.ImperativeOnlyPluginApplicator.applyImperative(ImperativeOnlyPluginApplicator.java:35)
at org.gradle.api.internal.plugins.RuleBasedPluginApplicator.applyImperative(RuleBasedPluginApplicator.java:43)
at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(DefaultPluginManager.java:144)
… 98 more

Any idea what might be the root cause, or how to fix that?

I was able to workaround this by changing order of the subproject definition in the main build script.

The referenced project dependencies ( via “compile project(’:xxx’)” notation) must be defined first, then it works.