Java-gradle-plugin and idea plugin incompatibilities

Gradle Version: 2.14.1
Operating System and JVM version: Ubuntu 14.04, java 1.8.0_91
Is this a regression? No

I’m writing a plugin and added the ‘java-gradle-plugin’ plugin to use with GradleRunner for testing purposes. it appears that using that plugin in concert with the ‘idea’ plugin causes some weird behavior. I’m using the command ./gradlew idea to generate my IDE project. When I do so, the file: build/pluginUnderTestMetadata/ gets added to the intellij module as a test dependency. That file puts build/classes/main and build/resources/main on the ‘implementation-classpath’.

The net result of this is that despite running tests from within intellij, it seems to be using the classes compiled by the gradle command line build. It’s not clear to me if both intellij’s compiled classes and gradle’s compiled classes are both available or if it always uses only gradle’s, but either way the behavior is very unintuitive as I must switch back and forth between running my tests in my ide and recompiling on the command line if I’m making modifications to the main source set.

I tried manually removing the dependency and this causes my tests to not even start, so excluding that file isn’t a viable workaround for this.

This is the expected behavior, TestKit uses exactly the same classpath as your main sourceSet. This is necessary to isolate the build under test from other dependencies in the test VM (e.g. JUnit). You don’t have to switch to the command line though, you can launch the compile task from IntelliJ.

This would be simpler if IntelliJ supported Gradle’s test execution feature (which executes tests in the Gradle build and returns the test result to the IDE). I will get in touch with them and see if we can make that feature happen.