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

(Mike Meessen) #1

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$
        at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(
        at org.gradle.configuration.BuildScriptProcessor.evaluate(
        at org.gradle.configuration.LifecycleProjectEvaluator.evaluate(
        at org.gradle.api.internal.project.AbstractProject.evaluate(
        at org.gradle.api.internal.project.AbstractProject.evaluate(
        at org.gradle.configuration.ProjectEvaluationConfigurer.execute(
        at org.gradle.configuration.ProjectEvaluationConfigurer.execute(
        at org.gradle.api.internal.Actions$CompositeAction.execute(
        at org.gradle.api.internal.Actions$TransformingActionAdapter.execute(
        at org.gradle.api.internal.project.AbstractProject.configure(
        at org.gradle.api.internal.project.AbstractProject.allprojects(
        at org.gradle.configuration.DefaultBuildConfigurer.configure(
        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(
        at org.gradle.initialization.DefaultGradleLauncher.doBuild(
        at org.gradle.launcher.exec.InProcessGradleLauncherActionExecuter.execute(
        at org.gradle.launcher.exec.InProcessGradleLauncherActionExecuter.execute(
        at org.gradle.api.internal.Actions$RunnableActionAdapter.execute(
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(
        at org.gradle.launcher.Main.doAction(
        at org.gradle.launcher.Main.main(
        at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(
        at org.gradle.launcher.GradleMain.main(
Caused by: org.gradle.api.GradleException: Could not generate a proxy class for class com.mycompany.MyTask.
        at org.gradle.api.internal.AbstractClassGenerator.generate(
        at org.gradle.api.internal.project.taskfactory.TaskFactory.createTaskObject(
        at org.gradle.api.internal.project.taskfactory.TaskFactory.createTask(
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory.createTask(
        at org.gradle.api.internal.project.taskfactory.DependencyAutoWireTaskFactory.createTask(
        at org.gradle.api.internal.tasks.DefaultTaskContainer.add(
        at org.gradle.api.internal.project.AbstractProject.task(
        at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMethod(
        at org.gradle.api.internal.BeanDynamicObject.invokeMethod(
        at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(
        at org.gradle.groovy.scripts.BasicScript.methodMissing(
        at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$
        ... 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(
        at org.gradle.api.internal.AsmBackedClassGenerator$ClassBuilderImpl.generate(
        at org.gradle.api.internal.AbstractClassGenerator.generate(
        ... 44 more
Caused by: java.lang.ClassFormatError: Duplicate method name&signature in class file com/mycompany/MyTask_Decorated
        at org.gradle.util.JavaMethod.invoke(
        ... 46 more

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

(Peter Niederwieser) #2

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

(Mike Meessen) #3

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

(Peter Niederwieser) #4

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

(Mike Meessen) #5

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:

Edit the task class was compiled with Gradle 1.3 btw.

(Mike Meessen) #6

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

(Mike Meessen) #7

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

(Peter Niederwieser) #8

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.

(Luke Daley) #9


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

(Mike Meessen) #10

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

(Mike Meessen) #11


(michael.wagner6) #12

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?

(Luke Daley) #13

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.

(michael.wagner6) #14

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

(Mike Meessen) #15

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:

(michael.wagner6) #16


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

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.

(Luke Daley) #17

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

(Luke Daley) #18

Raised as GRADLE-2695.

(Mike Meessen) #19

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

(Mike Meessen) #20

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