Custom Gradle distro with buildscript.dependencies.classpath breaks Grails 3

We’re having issues running Grails 3 applications without our custom Gradle distribution. The main point of our distribution is to configure internal repositories and plugins. I using Grails 3.0.4. The custom distro is built on Gradle 2.5.

Snippets from the Grails failure:

$ grails war --stacktrace
...
* What went wrong:
Execution failed for task ':findMainClass'.
> groovyjarjarasm.asm.Type.getMethodType(Lgroovyjarjarasm/asm/Type;[Lgroovyjarjarasm/asm/Type;)Lgroovyjarjarasm/asm/Type;


Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.grails.io.support.MainClassFinder
        at org.grails.gradle.plugin.run.FindMainClassTask.createMainClassFinder(FindMainClassTask.groovy:61)
        at org.grails.gradle.plugin.run.FindMainClassTask.findMainClass(FindMainClassTask.groovy:51)
        at org.grails.gradle.plugin.run.FindMainClassTask.setMainClassProperty(FindMainClassTask.groovy:25)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:75)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.doExecute(AnnotationProcessingTaskFactory.java:226)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:219)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:208)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:585)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:568)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
        ... 69 more

I’ve isolated the following in our init.d scripts:

    dependencies {
        classpath 'com.mutualofomaha:gradle-plugins:3.+'
    }

If I remove that, the grails command runs.

With the distribution in place, I get the following versions. I thought it might be a groovy version problem, but it doesn’t appear so. The groovyjarjarasm.asm.Type class looks identical between groovy 2.3.10 and 2.4.4.

$ ./gradlew --version

------------------------------------------------------------
Gradle 2.5
------------------------------------------------------------

Build time:   2015-07-08 07:38:37 UTC
Build number: none
Revision:     093765bccd3ee722ed5310583e5ed140688a8c2b

Groovy:       2.3.10
Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM:          1.7.0_40 (Oracle Corporation 24.0-b56)
OS:           Windows 7 6.1 amd64


$ grails --version
|Grails Version: 3.0.4
|Groovy Version: 2.4.4
|JVM Version: 1.7.0_40

I think I’ll need additional information before we can get to a potential solution:

  1. Which of your plugins do you actually need to apply to that project? I’d assume you only need a subset of them. Looking at your dependencies declaration it seems like you apply all of them. Is this really needed? I am trying to find out which of the plugins is causing the issue.
  2. Also Grails 3.x comes with its own ecosystem of Gradle configuration. The only plugin I think is helpful for a Grails project would be a definition of your internal binary repositories. Is that correct? If that’s the case, I’d probably try to break out that plugin and only declare that as plugin dependency without having to use your custom distribution.
  3. To me the exception looks like an incompatibility issue with Groovy of some sort. Did you try out the Groovy upward compatibility library?

Some of the plugins are used for applying corporate source and deployable conventions. Others are to support the build pipeline and reduce configuration. Our Grails 3 applications would use about 6 of the 14 plugins.

The current set of dependencies in the plugin project is:

compile 'org.codehaus.groovy.modules.http-builder:http-builder:0.7.1’
compile 'org.apache.httpcomponents:httpclient:4.3.4’
compile 'de.aaschmid.gradle.plugins:gradle-cpd-plugin:0.4’
compile 'com.netflix.nebula:gradle-dependency-lock-plugin:1.12.5’
compile 'org.jfrog.buildinfo:build-info-extractor-gradle:3.1.1’
compile 'com.google.guava:guava:18.0’
compile ‘com.terrafolio:gradle-jenkins-plugin:1.3.1’

testCompile 'org.spockframework:spock-core:1.0-groovy-2.3@jar’
testCompile(‘com.netflix.nebula:nebula-test:2.2.2’) {
exclude(module: ‘groovy-all’)
}
testCompile ‘cglib:cglib-nodep:3.1’

I don’t see factoring out the 6 plugins reducing that much.

I thought it may be a Groovy version issue too. I compared the Gradle dependencies and couldn’t find the difference. I’ll try the upward compat library and see if it helps.

Make sure to compare the dependencies (and the picked versions) based on the dependency report (gradle dependencies) and not the declared, top-level dependencies in your build.

I compared gradle dependencies and grails dependency-report for both working and broken configurations. Meaning I removed the offending code out of the custom distro to make it work. Both dependency reports are identical. They are using groovy 2.4.4.

We upgraded to Gradle 2.6 and the problem went away.