Java.lang.ClassFormatError: Duplicate method name&signature in custom task's class file after upgrading to Gradle 1.3

Hi there,

I’m a bit late to the party this time :wink: But I’m currently upgrading our project builds to Gradle 1.3.

I’m having issues with one of our tasks. I didn’t change its code between 1.1 and 1.3 and it compiles fine under all three versions. However, when I reference it in a build file as simple as this one:

buildscript {
    repositories {
        mavenRepo name: "universe", url: "http://companyRepoServer/"
    }
      dependencies {
        classpath (
            [group: 'com.mycompany', name: 'my-tasks', version: 'SNAPSHOT']
        )
    }
}
  import com.mycompany.MyTask
  apply plugin: 'java'
  task somTask (type: MyTask) {
 // nothing
}

gradle aborts during configuration with the following error:

* Where:
Build file 'D:\tmp\gradle-test-proj\build.gradle' line: 18
  * What went wrong:
A problem occurred evaluating root project 'gradle-test-proj'.
> Could not generate a proxy class for class com.mycompany.MyTask.
  * Try:
Run with --info or --debug option to get more log output.
  * Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating root project 'gradle-test-proj'.
        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.api.internal.Actions$CompositeAction.execute(Actions.java:67)
        at org.gradle.api.internal.Actions$TransformingActionAdapter.execute(Actions.java:96)
        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:32)
        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.api.internal.Actions$RunnableActionAdapter.execute(Actions.java:137)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139)
        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.GradleException: Could not generate a proxy class for class com.mycompany.MyTask.
        at org.gradle.api.internal.AbstractClassGenerator.generate(AbstractClassGenerator.java:201)
        at org.gradle.api.internal.project.taskfactory.TaskFactory.createTaskObject(TaskFactory.java:105)
        at org.gradle.api.internal.project.taskfactory.TaskFactory.createTask(TaskFactory.java:70)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory.createTask(AnnotationProcessingTaskFactory.java:93)
        at org.gradle.api.internal.project.taskfactory.DependencyAutoWireTaskFactory.createTask(DependencyAutoWireTaskFactory.java:39)
        at org.gradle.api.internal.tasks.DefaultTaskContainer.add(DefaultTaskContainer.java:50)
        at org.gradle.api.internal.project.AbstractProject.task(AbstractProject.java:916)
        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_21nm0ea1t3edkqi880mlpe13sn.run(D:\tmp\gradle-test-proj\build.gradle:18)
        at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:52)
        ... 32 more
Caused by: org.gradle.api.GradleException: Could not call ClassLoader.defineClass() on org.gradle.util.MutableURLClassLoader@35de4376
        at org.gradle.util.JavaMethod.invoke(JavaMethod.java:62)
        at org.gradle.api.internal.AsmBackedClassGenerator$ClassBuilderImpl.generate(AsmBackedClassGenerator.java:819)
        at org.gradle.api.internal.AbstractClassGenerator.generate(AbstractClassGenerator.java:199)
        ... 44 more
Caused by: java.lang.ClassFormatError: Duplicate method name&signature in class file com/mycompany/MyTask_Decorated
        at org.gradle.util.JavaMethod.invoke(JavaMethod.java:56)
        ... 46 more
    BUILD FAILED

I read that you switched ASM versions in Gradle 1.2, but when I use 1.2 at runtime, everything works fine. The problems start when using Gradle 1.3 for building projects that rely on the custom task.

Any idea?

Best regards, Mike

Do you get the same error when compiling the plugin against 1.3, and then using that in a 1.3 build?

Yes I do; it looks as if the runtime is relevant, not the compiled class file.

Can you provide a reproducible example? Then we can have a closer look.

Okay, so I compiled my task into a jar and created a minimal project reproducing the error. If you just run “gradle tasks” with gradle 1.2, it works. If you run it with gradle 1.3, it fails.

Here’s the project archive: https://docs.google.com/file/d/0B6hxwnTm7cjybXhNcnFZR0VMcU0/edit

Edit the task class was compiled with Gradle 1.3 btw.

Update: tested with Gradle 1.4: same result as with 1.3, even when compiling the task with 1.4

Any update here? This is really a blocker for us…

At the moment, it isn’t clear to me that the problem is on Gradle’s side. If you can provide a minimal reproducible example that allows to build the task from source, I might have another look.

Hi,

Can you please provide the source for the task class. I can’t proceed without it.

Oh, sure, here’s the gradle project that builds the “failingTask.jar” file used in the sample project above.

https://docs.google.com/file/d/0B6hxwnTm7cjybGR3NFR6UXhORnM/edit?usp=sharing

push

Hi, I tried out the example and run into the same problem. I would be interested in the solution, too. Is there an example of a Java-Task class?

I haven’t worked out exactly why, but it’s the ‘fileMapping(File, File)’ and ‘fileMapping(File)’ methods that trigger this. If you rename them it should work.

I’m still looking into exactly why this happens.

Thanks, Luke. On my side it is working now if I rename the methods like you suggested.

Thanks for pointing us at the right method and coming up with a workaround, Luke.

Changing that method’s name would break the task’s “api” though, and force all our projects to not only update to a new version of the task but also change actual project build files when migrating to the newer gradle versions… I still hope you can find the cause for this and maybe fix it for 1.5 … I think we might migrate directly from 1.2 to 1.5 if it fixes the issue without having to adapt all project build files.

Looking forward to hearing from you! :slight_smile:

Hi,

as a newbie to gradle I found this topic very interesting. So I re-arranged your example to have a buildSrc directory:

www.gradle.org/docs/current/userguide/organizing_build_logic.html#sec:build_sources http://stackoverflow.com/questions/13874680/what-is-the-purpose-of-gradles-buildsrc-folder/13875350#13875350

With this I only have to rename one method:

public void fileMappingX(File input) {

Perhaps you can replace all fileMapping(file) calls with fileMapping(file, null) ? No pretty solution either.

Unfortunately this won’t make 1.5, which is close to RC stage.

Raised as GRADLE-2695.

Now that 1.5 is released: Go go go! I’m eager to jump to the latest Gradle again! :smiley:

Any update here? Doesn’t look like this is getting much attention :frowning: