When importing an ant build.xml, I get a ConcurrentModificationException

Hi Guys,

I am looking to move our existing ant infrastructure to Gradle progressively. As such, I am importing an ant build and just trying to run the ant tasks from gradle.

Our build environment uses Ivy and Ant.

The setup is a basic build.xml that imports a large build-common-ant.xml that imports a large build-common-ivy.xml. Most of the tasks work, however, every now and again I hit a ConcurrentModificationException.

It sometimes gets resolved by specifying the and target to as build-common.export instead of just export.I haven’t been able to assemble a small example that exhibits this behavior yet.

Here’s the stack trace:

* Exception is:
java.util.ConcurrentModificationException
        at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.removeShouldRunAfterSuccessorsIfTheyImposeACycle(DefaultTaskExecutionPlan.java:298)
        at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.determineExecutionPlan(DefaultTaskExecutionPlan.java:223)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.ensurePopulated(DefaultTaskGraphExecuter.java:150)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:84)
        at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
        at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
        at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:68)
        at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:62)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:55)
        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:149)
        at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
        at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:80)
        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:36)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
        at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:51)
        at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:237)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:210)
        at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:35)
        at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:206)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)
        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:33)
        at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:54)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35)
        at org.gradle.launcher.GradleMain.main(GradleMain.java:23)

I am running the latest 2.1 release of Gradle.

If someone can point me in the right direction to investigate?

Thanks, Marc

Hello Marc,

thanks for reporting this. It would be really helpful to get a reproducable example working that lets us dig deeper into this. I raised GRADLE-3166 to track this issue in the gradle issue tracker.

Hi Rene,

Thanks for the quick reply. I was able to find a relatively simple item that fails as well.

I’ve posted 4 files here: https://gist.github.com/anonymous/6a3660c787319ccb285b#file-build-gradle

Broken from Gradle:

$ gradle service-version
:build-number
  FAILURE: Build failed with an exception.
  * What went wrong:
java.util.ConcurrentModificationException (no error message)
  * Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
  BUILD FAILED
  Total time: 1.604 secs
$

Working from ANT:

$ ant service-version
Buildfile: /home/mrawji/workspaces/gradle/broken/build.xml
  init:
  resolve:
  build-number:
  service-version:
  BUILD SUCCESSFUL
Total time: 0 seconds
$

If the build-common-ant-ivy.xml has the part of it commented out (see comments in the file)

$ gradle service-version
:build-number
:init
:resolve
:build-number
:service-version
  BUILD SUCCESSFUL
  Total time: 1.653 secs
$

Thanks for the instructions to reproduce. I’ve added this to the schedule to look at before the release of 2.2.

If it helps in any way, this problem seem to happen starting from 1.12. Works fine since 1.11. Although, 1.11 is broken for ant target dependency resolution.

I am trying to do the same, but not getting java.util.ConcurrentModificationException. In my case, Gradle can not load the Ivy library. In this case, where is Ivy library located?