0

When applying my own custom plugin which in turn applies groovy (plugin), it fails with Failed to apply plugin [id 'groovy'] which is caused by java.lang.IllegalStateException: model 'tasks' is finalized thrown from org.gradle.model.internal.registry.DefaultModelRegistry.assertNotFinalized

Is it somehow impossible to apply groovy from another plugin? Or what am I missing here?

The project where my plugin is applied:

buildscript {
    repositories {
        mavenCentral()
        maven {
            url file( '../../maven-deploy' )
        }
    }
    dependencies {
        // will be loaded from maven-deploy, not mavenCentral().
        classpath 'se.toxbee.robospock:gradle-plugin-robospock:0.1.0'
    }
}

apply plugin: 'robospock'

And the code where groovy is applied:

def applyGroovy( RoboSpockConfiguration cfg ) {
    def p = cfg.project
    if ( !p.plugins.hasPlugin( 'groovy' ) ) {
        p.apply plugin: 'groovy'
    }
}

The stacktrace: http://pastebin.com/ikXJTM67

The git repo: https://github.com/Centril/gradle-plugin-robospock (the README.md here is not accurate, don't read it...)

The application of groovy happens in an afterEvaluate closure, is this relevant perhaps?

If I add p.apply plugin: 'eclipse' before the failing line, it doesn't fail due to eclipse, so applying plugins in general is not prohibited.

pixel
  • 24,905
  • 36
  • 149
  • 251
Centril
  • 2,549
  • 1
  • 22
  • 30

1 Answers1

0

This seems to be due to afterEvaluate - when the application of the groovy plugin is moved out of that closure but still in the plugin, it works fine.

However, I am not exactly sure as to why this is the case, just that it is. Anyone who knows should feel free to edit my answer or post a comment.

Centril
  • 2,549
  • 1
  • 22
  • 30
  • This will be fixed according to Luke Daley @ Gradle Core Dev in Gradle 2.2, see: http://forums.gradle.org/gradle/topics/plugin-in-afterevaluate-failed-to-apply-plugin-id-groovy-model-tasks-is-finalized – Centril Oct 28 '14 at 08:16