maiflai / gradle-scalatest

A plugin to enable the use of scalatest in a gradle Scala project.
The Unlicense
73 stars 35 forks source link

Plugin causes double-addition of jacoco agent to test command line #44

Closed tfenne closed 7 years ago

tfenne commented 7 years ago

I'm not a gradle expert, and so this was pretty painful for me to track down. I'm converting an existing gradle build and Java codebase to using scalatest for testing. Upon installing the grade-scalatest plugin my tests spewed massive amounts of exceptions about not being able to instrument classes that were already instrumented.

Running gradle in debug mode showed that the jacoco agent was getting added twice on the command line for the tests. After poking around a bunch I found JacocoTestAction.groovy which appears to add the jacoco JVM args.

I currently have the following in my gradle build and it is now working:

test.getActions().removeIf { a -> ("" + a.action).contains("com.github.maiflai.JacocoTestAction") }

I tried to build the plugin from source to try and test a fix, but I can't figure out how to make gradle load the plugin from my local disk/repo. I think the following change to JacocoTestAction.groovy should work in most cases:

// Added check that jvmArgs don't already contain the jacoco args
if (jacoco && jacoco.enabled && !task.jvmArgs.contains(jacoco.getAsJvmArg())) {
    task.jvmArgs jacoco.getAsJvmArg()
}
maiflai commented 7 years ago

Thanks for the detailed work, it's much appreciated.

I think you need to use the old-fashioned way of attaching a plugin in order to test locally; you can see this from src/test/examples/jacoco. The test build there uses the plugin that is built by the main build, but you could alternatively install to your local repo and then use mavenLocal()

Please could you share your build (or at least the Gradle version, this plugin's version and the versions of any other plugins that you have loaded)? The integration test above passes locally with a vanilla Gradle 3.3 build.

Thanks, Stu.

tfenne commented 7 years ago

Hi @maiflai, thanks for taking the time to look at it. The build I'm working on is here: https://github.com/samtools/htsjdk/pull/789

There are a lot of small changes in that PR (re-parenting all test classes), but the gradle build changes are what's important. The build is currently using gradle 3.2.1, but I did also try it under 3.3 and got the same results.

Thanks again for looking at the problem!

maiflai commented 7 years ago

Hi,

Sorry for the delay, I've released a fix which should enable you to remove the hack from your build.

Please could you upgrade and let me know how you get on?

    id 'com.github.maiflai.scalatest' version '0.15'
}
// test.getActions().removeIf { a -> ("" + a.action).contains("com.github.maiflai.JacocoTestAction") }
// testSRA.getActions().removeIf { a -> ("" + a.action).contains("com.github.maiflai.JacocoTestAction") 

Thanks, Stu.

tfenne commented 7 years ago

Thanks! I've updated our build to use 0.15 and it's working great.

maiflai commented 7 years ago

Great, glad to help.