Eclipse "whenmerged" hook fails when included in "subprojects" closure


(nathan) #1

I am using the “whenmerged” hook to modify the exported entries in the generated eclipse classpath as per the example in section 36.4.2.2 of the Gradle user guide. This works fine for a single project but if I move it to the “subprojects” closure in the root project then the build fails with the following error message:

Could not find method whenMerged() for arguments [build_22ci319j0o3fipj4dom75lr8dj$_run_closure2_closure4_closure5@71dd95c]

The subproject configuration is like the following:

subprojects {
 apply plugin: 'eclipse'
 eclipse.classpath.file {
  whenMerged { classpath ->
   classpath.entries.findAll { entry -> entry.kind != 'output' }*.exported = false
  }
 }
}

(Luke Daley) #2

Can you please provide the full error message. There’s a section about which object the ‘whenMerged()’ method is actually being called on missing.

If in doubt, please just provide the whole output.


(nathan) #3

Hi Luke. Here is the entire output including stack trace.

nathan@deadveal:~/Development/Code/juzidian$ gradle eclipse --stacktrace

FAILURE: Build failed with an exception.

  • Where: Build file ‘/home/nathan/Development/Code/juzidian/build.gradle’ line: 28

  • What went wrong: A problem occurred evaluating root project ‘juzidian’. > Could not find method whenMerged() for arguments [build_22ci319j0o3fipj4dom75lr8dj$_run_closure2_closure5_closure6@12d91987] on root project ‘juzidian’.

  • Try: Run with --info or --debug option to get more log output.

  • Exception is: org.gradle.api.GradleScriptException: A problem occurred evaluating root project ‘juzidian’.

at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:54)

at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:127)

at org.gradle.configuration.BuildScriptProcessor.evaluate(BuildScriptProcessor.java:38)

at org.gradle.configuration.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:43)

at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:463)

at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:75)

at org.gradle.configuration.ProjectEvaluationConfigurer.execute(ProjectEvaluationConfigurer.java:23)

at org.gradle.configuration.ProjectEvaluationConfigurer.execute(ProjectEvaluationConfigurer.java:21)

at org.gradle.configuration.DefaultBuildConfigurer$1.execute(DefaultBuildConfigurer.java:38)

at org.gradle.configuration.DefaultBuildConfigurer$1.execute(DefaultBuildConfigurer.java:35)

at org.gradle.api.internal.project.AbstractProject.configure(AbstractProject.java:439)

at org.gradle.api.internal.project.AbstractProject.allprojects(AbstractProject.java:434)

at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:35)

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.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:38)

at org.gradle.launcher.exec.InProcessGradleLauncherActionExecuter.execute(InProcessGradleLauncherActionExecuter.java:39)

at org.gradle.launcher.exec.InProcessGradleLauncherActionExecuter.execute(InProcessGradleLauncherActionExecuter.java:25)

at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)

at org.gradle.launcher.cli.ActionAdapter.execute(ActionAdapter.java:30)

at org.gradle.launcher.cli.ActionAdapter.execute(ActionAdapter.java:22)

at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:200)

at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:173)

at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)

at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:138)

at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)

at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)

at org.gradle.launcher.Main.doAction(Main.java:48)

at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)

at org.gradle.launcher.Main.main(Main.java:39)

at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)

at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)

at org.gradle.launcher.GradleMain.main(GradleMain.java:26) Caused by: org.gradle.api.internal.MissingMethodException: Could not find method whenMerged() for arguments [build_22ci319j0o3fipj4dom75lr8dj$_run_closure2_closure5_closure6@12d91987] on root project ‘juzidian’.

at org.gradle.api.internal.AbstractDynamicObject.methodMissingException(AbstractDynamicObject.java:68)

at org.gradle.api.internal.AbstractDynamicObject.invokeMethod(AbstractDynamicObject.java:56)

at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:172)

at org.gradle.groovy.scripts.BasicScript.methodMissing(BasicScript.java:83)

at build_22ci319j0o3fipj4dom75lr8dj$_run_closure2_closure5.doCall(/home/nathan/Development/Code/juzidian/build.gradle:28)

at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:141)

at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:90)

at org.gradle.util.ConfigureUtil$configure.call(Unknown Source)

at org.gradle.plugins.ide.eclipse.model.EclipseClasspath.file(EclipseClasspath.groovy:189)

at org.gradle.plugins.ide.eclipse.model.EclipseClasspath_Decorated.file(Unknown Source)

at org.gradle.plugins.ide.eclipse.model.EclipseClasspath_Decorated$file.call(Unknown Source)

at build_22ci319j0o3fipj4dom75lr8dj$_run_closure2.doCall(/home/nathan/Development/Code/juzidian/build.gradle:27)

at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:141)

at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:90)

at org.gradle.api.internal.project.AbstractProject.configure(AbstractProject.java:861)

at org.gradle.api.internal.project.AbstractProject.configure(AbstractProject.java:866)

at org.gradle.api.internal.project.AbstractProject.subprojects(AbstractProject.java:849)

at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(BeanDynamicObject.java:216)

at org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObject.java:122)

at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(CompositeDynamicObject.java:147)

at org.gradle.groovy.scripts.BasicScript.methodMissing(BasicScript.java:83)

at build_22ci319j0o3fipj4dom75lr8dj.run(/home/nathan/Development/Code/juzidian/build.gradle:15)

at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:52)

… 33 more

BUILD FAILED

Total time: 4.847 secs


(Szczepan Faber) #4

The problem is because classpath file is not generated for all projects but only for projects that have the java plugin (strictly speaking: the JavaBase plugin). To fix the problem you can:

subprojects {
  plugins.withType(JavaBase) {
    eclipse.classpath.file {
        ...
    }
  }
}

The exception is not great. We should definitely improve Gradle’s bahavior in this scenario. I’ll create a jira ticket for it.

Hope that helps!


(nathan) #5

Thanks Szczepan. In my case the subproject that is not applying the java plugin is an android project which instead uses the android plugin (http://tools.android.com/tech-docs/new-build-system/). The above fix worked after I changed “JavaBase” to “org.gradle.api.plugins.JavaBasePlugin”.