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') {


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(
at org.gradle.model.internal.registry.DefaultModelRegistry.access$500(
at org.gradle.model.internal.registry.DefaultModelRegistry$ModelElementNode.addLink(
at org.gradle.api.internal.tasks.DefaultTaskContainer.addPlaceholderModelLink(
at org.gradle.api.internal.tasks.DefaultTaskContainer.addPlaceholderAction(
at org.gradle.language.base.plugins.LifecycleBasePlugin.addClean(
at org.gradle.language.base.plugins.LifecycleBasePlugin.apply(
at org.gradle.language.base.plugins.LifecycleBasePlugin.apply(
at org.gradle.api.internal.plugins.ImperativeOnlyPluginApplicator.applyImperative(
at org.gradle.api.internal.plugins.RuleBasedPluginApplicator.applyImperative(
at org.gradle.api.internal.plugins.DefaultPluginManager.doApply(
… 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.