How do I use JMockit with Gradle on the IBM J9 JVM?
gradle, jmockit, junit
Solution
This is http://issues.gradle.org/browse/GRADLE-2189, which is already fixed for the upcoming 1.0-rc-1. You can try out the release candidate today.
Problem
I'm using Gradle (Milestone 8a) to run JUnit tests on my project with the IBM J9 JVM, which according to "Running tests with JMockit" requires that I pass the argument `-javaagent:jmockit.jar` to the JVM. However, JMockit isn't injecting mocked parameters which is causing my tests to fail with "Method (foo) should have no parameters)". The tests run fine in Eclipse on the HotSpot JVM. I've extended the `test` task to find the JAR and add the argument to `jvmArgs` like this: ``` test { doFirst { // Don't do this until the task is actually being executed, because // as soon as we call testCompile.find the configuration is resolved and // can't be modified anymore. jMockit = project.configurations.testCompile.find { it.name.startsWith("jmockit-") } jvmArgs "-javaagent:${jMockit}" } } ``` I've also added JMockit and JUnit to the `testCompile` configuration, making sure that JMockit is first, and verified this by running `gradle dependencies`: ``` dependencies { testCompile 'com.googlecode.jmockit:jmockit:0.999.13' testCompile 'junit:junit:4.10' } ``` The output of `gradle check --debug` confirms that the `-javaagent` parameter is being used: ``` 12:44:14.788 [DEBUG] [org.gradle.process.internal.ProcessBuilderFactory] creating process builder for Gradle Worker 1 12:44:14.788 [DEBUG] [org.gradle.process.internal.ProcessBuilderFactory] in directory /home/bbobby/webapp 12:44:14.788 [DEBUG] [org.gradle.process.internal.ProcessBuilderFactory] with argument#0 = -javaagent:/home/bbobby/.gradle/caches/artifacts-8/filestore/com.googlecode.jmockit/jmockit/0.999.13/jar/a6 ba457e09361f37e386edea176c5ce4fa9ee110/jmockit-0.999.13.jar 12:44:14.789 [DEBUG] [org.gradle.process.internal.ProcessBuilderFactory] with argument#1 = -ea 12:44:14.789 [DEBUG] [org.gradle.process.internal.ProcessBuilderFactory] with argument#2 = -cp 12:44:14.789 [DEBUG] [org.gradle.process.internal.ProcessBuilderFactory] with argument#3 = /home/bbobby/.gradle/caches/1.0-milestone-8a/workerMain/classes 12:44:14.789 [DEBUG] [org.gradle.process.internal.ProcessBuilderFactory] with argument#4 = org.gradle.process.internal.launcher.GradleWorkerMain 12:44:14.816 [DEBUG] [org.gradle.process.internal.DefaultExecHandle] Started Gradle Worker 1. ``` I'm pretty sure I've done everything I'm supposed to. Why are my tests failing to run?