[GRADLE-3069] Gradle 1.12-rc-1 Script Plugin classpath issues Created: 17/Apr/14  Updated: 17/Apr/14  Resolved: 17/Apr/14

Status: Resolved
Project: Gradle
Affects Version/s: None
Fix Version/s: 1.12-rc-2

Type: Task
Reporter: Gradle Forums Assignee: Luke Daley
Resolution: Fixed Votes: 0


 Description   

Trying to upgrade to 1.12-rc-1 and I encounter an error where the classpath for a plugin script appears to be wrong:

project/

+ – buildSrc/

 
-- build.gradle

+ – build.gradle

+ – grails-app.gradle

+ – grails.gradle

So the scenarios is this:
buildSrc/build.gradle contains

repositories {
jcenter()
}
dependencies {
compile 'org.grails:grails-gradle-plugin:2.0.1'
}

Then build.gradle is:

apply from: file('grails-app.gradle')

And grails.gradle is:

apply from: file('grails.gradle')

And finally 'grails-base.gradle' is:

import org.grails.gradle.pluigin.tasks.GrailsTask

apply plugin: 'grails'
version = '1.0'
grails {
grailsVersion = '2.3.5'
groovyVersion = '2.1.9'
}
repositories {
grails.central()
}
dependencies {
bootstrap 'org.grails.plugins:tomcat:7.0.50'
compile 'org.grails.plugins:scaffolding:2.0.0'
}

task testFoo(type: GrailsTask) {
command 'test-app'
}

When trying to run Gradle get the following error:

➜ gg-test gradle tasks -s
:buildSrc:compileJava UP-TO-DATE
:buildSrc:compileGroovy UP-TO-DATE
:buildSrc:processResources UP-TO-DATE
:buildSrc:classes UP-TO-DATE
:buildSrc:jar UP-TO-DATE
:buildSrc:assemble UP-TO-DATE
:buildSrc:compileTestJava UP-TO-DATE
:buildSrc:compileTestGroovy UP-TO-DATE
:buildSrc:processTestResources UP-TO-DATE
:buildSrc:testClasses UP-TO-DATE
:buildSrc:test UP-TO-DATE
:buildSrc:check UP-TO-DATE
:buildSrc:build UP-TO-DATE

FAILURE: Build failed with an exception.

  • Where:
    Script '/Users/jengelman/workspace/personal/gg-test/grails.gradle'
  • What went wrong:
    A problem occurred evaluating script.
    > org.grails.gradle.plugin.tasks.GrailsTask
  • Try:
    Run with --info or --debug option to get more log output.
  • Exception is:
    org.gradle.api.GradleScriptException: A problem occurred evaluating script.
    at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:54)
    at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:152)
    at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.applyScript(DefaultObjectConfigurationAction.java:97)
    at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.access$000(DefaultObjectConfigurationAction.java:36)
    at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction$1.run(DefaultObjectConfigurationAction.java:67)
    at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.execute(DefaultObjectConfigurationAction.java:129)
    at org.gradle.groovy.scripts.DefaultScript.apply(DefaultScript.java:99)
    at org.gradle.api.Script$apply.callCurrent(Unknown Source)
    at grails_app_67id415ckdhs09fpd03ja43j2q.run(/Users/jengelman/workspace/personal/gg-test/grails-app.gradle:1)
    at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:52)
    at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:152)
    at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.applyScript(DefaultObjectConfigurationAction.java:97)
    at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.access$000(DefaultObjectConfigurationAction.java:36)
    at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction$1.run(DefaultObjectConfigurationAction.java:67)
    at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.execute(DefaultObjectConfigurationAction.java:129)
    at org.gradle.api.internal.project.AbstractPluginAware.apply(AbstractPluginAware.java:41)
    at org.gradle.api.Project$apply.call(Unknown Source)
    at org.gradle.api.internal.project.ProjectScript.apply(ProjectScript.groovy:34)
    at org.gradle.api.Script$apply.callCurrent(Unknown Source)
    at build_2e86hqli4nat0hh88fge0ivsta.run(/Users/jengelman/workspace/personal/gg-test/build.gradle:1)
    at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:52)
    at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:152)
    at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:40)
    at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:26)
    at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:34)
    at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:55)
    at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:493)
    at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:80)
    at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:31)
    at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:142)
    at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
    at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64)
    at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
    at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
    at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35)
    at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:45)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
    at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:42)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
    at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:24)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
    at org.gradle.launcher.daemon.server.exec.StartStopIfBuildAndStop.execute(StartStopIfBuildAndStop.java:33)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
    at org.gradle.launcher.daemon.server.exec.ReturnResult.execute(ReturnResult.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:71)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:69)
    at org.gradle.util.Swapper.swap(Swapper.java:38)
    at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:69)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
    at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
    at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:60)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:45)
    at org.gradle.launcher.daemon.server.DaemonStateCoordinator.runCommand(DaemonStateCoordinator.java:186)
    at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy.doBuild(StartBuildOrRespondWithBusy.java:49)
    at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
    at org.gradle.launcher.daemon.server.exec.HandleStop.execute(HandleStop.java:36)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
    at org.gradle.launcher.daemon.server.exec.DaemonHygieneAction.execute(DaemonHygieneAction.java:39)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
    at org.gradle.launcher.daemon.server.exec.CatchAndForwardDaemonFailure.execute(CatchAndForwardDaemonFailure.java:32)
    at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
    at org.gradle.launcher.daemon.server.exec.DefaultDaemonCommandExecuter.executeCommand(DefaultDaemonCommandExecuter.java:51)
    at org.gradle.launcher.daemon.server.DefaultIncomingConnectionHandler$ConnectionWorker.handleCommand(DefaultIncomingConnectionHandler.java:155)
    at org.gradle.launcher.daemon.server.DefaultIncomingConnectionHandler$ConnectionWorker.receiveAndHandleCommand(DefaultIncomingConnectionHandler.java:128)
    at org.gradle.launcher.daemon.server.DefaultIncomingConnectionHandler$ConnectionWorker.run(DefaultIncomingConnectionHandler.java:116)
    at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:64)
    Caused by: java.lang.NoClassDefFoundError: org.grails.gradle.plugin.tasks.GrailsTask
    at grails_5ll5nj66lcs9b212v4b2fcl4tv.class$(/Users/jengelman/workspace/personal/gg-test/grails.gradle)
    at grails_5ll5nj66lcs9b212v4b2fcl4tv.$get$$class$org$grails$gradle$plugin$tasks$GrailsTask(/Users/jengelman/workspace/personal/gg-test/grails.gradle)
    at grails_5ll5nj66lcs9b212v4b2fcl4tv.run(/Users/jengelman/workspace/personal/gg-test/grails.gradle:21)
    at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:52)
    ... 73 more

If I remove one of the nestings, change build.gradle to be:

apply from: file('grails.gradle')

Then the file resolves fine and the build will run.

This build works fine in Gradle 1.11.



 Comments   
Comment by Gradle Forums [ 17/Apr/14 ]

So the only place where you are declaring `grails-gradle-plugin` is ` buildSrc/build.gradle`? Then you can use it only for the `buildSrc` build. If you want to use it for the main build, you need a `buildscript` block in `build.gradle`.

Comment by Gradle Forums [ 17/Apr/14 ]

Ok, that works. Which isn't overly surprising, except this wasn't an issue before and previously when I did this, I would get class loader conflicts.

But now I don't seem to be able to replicate that issue.

Question -> if I apply a `buildscript` block in the main `build.gradle` file, should those classes be available in any applied script or are they isolated and I need to apply the same `buildscript` block in each one?

It seems like when doing an `apply from: file` that script to be loaded should extend from the classloader of the parent, but that doesn't seem to be the case.

Comment by Gradle Forums [ 17/Apr/14 ]

Currently, the `buildscript` block needs to go into the project's main build script, and does affect scripts applied to the main script.

Comment by Gradle Forums [ 17/Apr/14 ]

Thanks Peter, but it doesn't seem to be working that way.

It works correctly for one level of nesting:
build.gradle -> apply -> grails.gradle

but not deeper:
build.gradle -> apply -> grails.gradle -> apply -> grails2.gradle

Furthermore, it appears that classes from the `buildSrc` build are not available in the 2nd level (grails2.gradle) file.

Comment by Gradle Forums [ 17/Apr/14 ]

Can you try with 1.11? Might be a regression in 1.12-rc-1.

Comment by Gradle Forums [ 17/Apr/14 ]

Works in 1.11.

Here is an example project: [1]https://github.com/johnrengelman/grai...

Under Gradle 1.11 it works fine (this actually shows the `buildSrc` dependencies being availble for all subsequent scripts...which makes sense to me because it's `buildSrc` inherently placed onto the classpath? shouldn't all it's dependencies be placed there, too?)

Under Gradle 1.12 this fails, unless you explicitly add a `buildscript` block to the `gradle-base.gradle` file (which only fixes the `GrailsTask` dependency, but the classes from `buildSrc` are not available)
----------------------------------------------------------------------------------------
[1] https://github.com/johnrengelman/grails-gradle-112

Generated at Wed Jun 30 12:39:05 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.