[GRADLE-2620] Eclipse classpath.file.whenMerged hook breaks confusingly for non-java projects Created: 09/Jan/13  Updated: 10/Feb/17  Resolved: 10/Feb/17

Status: Resolved
Project: Gradle
Affects Version/s: None
Fix Version/s: None

Type: Bug
Reporter: Gradle Forums Assignee: Unassigned
Resolution: Won't Fix Votes: 0


 Description   
subprojects {
  apply plugin: 'eclipse'
  eclipse.classpath.file.whenMerged { }
}

Above only works if the subproject has a JavaBase plugin applied. If not various script compile time errors occur, for example:

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

We should look into ways of improving the dsl / error message and perhaps review the samples / docs that mention classpath.file.whenMerged feature.

Workarounds:

1. Apply java plugin (or some other plugin, that also applies JavaBase plugin) before applying the eclipse plugin.
2. Use plugins.withType:

subprojects {
  apply plugin: 'eclipse'
  plugins.withType(JavaBase) {
    //now we can manipulate the .classpath file:
    eclipse.classpath.file.whenMerged {}
  }
}


 Comments   
Comment by Gradle Forums [ 09/Jan/13 ]

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.

Comment by Gradle Forums [ 09/Jan/13 ]

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

Comment by Gradle Forums [ 09/Jan/13 ]

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!

Comment by Benjamin Muschko [ 15/Nov/16 ]

As announced on the Gradle blog we are planning to completely migrate issues from JIRA to GitHub.

We intend to prioritize issues that are actionable and impactful while working more closely with the community. Many of our JIRA issues are inactionable or irrelevant. We would like to request your help to ensure we can appropriately prioritize JIRA issues you’ve contributed to.

Please confirm that you still advocate for your JIRA issue before December 10th, 2016 by:

  • Checking that your issues contain requisite context, impact, behaviors, and examples as described in our published guidelines.
  • Leave a comment on the JIRA issue or open a new GitHub issue confirming that the above is complete.

We look forward to collaborating with you more closely on GitHub. Thank you for your contribution to Gradle!

Comment by Benjamin Muschko [ 10/Feb/17 ]

Thanks again for reporting this issue. We haven't heard back from you after our inquiry from November 15th. We are closing this issue now. Please create an issue on GitHub if you still feel passionate about getting it resolved.

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