Bug in Jacoco Plugin

I’ve run into a bug with the Jacoco plugin, that seems to be caused either by Windows or by Java limitations for long path names. It happens when the “wrong” path is passed as -javaagent when spawning new JVMs. I am consistently seeing the problem with all combinations of:

  • Windows 10, Windows 8.1, Windows 7
  • Java 7, Java 8
  • Gradle 2.13, Gradle 3.0

This is how I recreate it:

  1. Save the contents of this pastebin to a file C:\reproduce.bat.
  2. Have Gradle on your PATH.
  3. Run the batch file. It will create some files and run gradle build, which will result in an error.
  4. Clean up by deleting C:\reproduce.bat and C:\my-server-root-directory.

The fix I’ve found is pretty short: Change this line [JacocoTaskExtension.java#L268] (https://github.com/gradle/gradle/blob/2a327629cf76ec1998a8c9b6db7a6ae306903edf/subprojects/jacoco/src/main/java/org/gradle/testing/jacoco/plugins/JacocoTaskExtension.java#L268) to use the absolute instead of the relative path. Ironically, this makes the path loner, but it solves the issue.

I have only seen this happen when the relative path moves up some directories, so a slightly less invasive fix would be to check if the relative path contains .. and use the absolute path in that case.

I haven’t taken the time to fully grok your issue but I had issues with jacoco on Windows with backslashes which was solved by replacing with forward slashes

More info here

1 Like

Thank you, Lance! That’s a nice workaround.

I still think this might be worth fixing. There will be more people running into this and similar issues with instrumentation in the future. The new Jenkins 2.x Pipelines scripts, tend to create workspaces with longer path names, which makes this more likely to occur.