Custom source set in Gradle imported into IntelliJ 14

I am trying to get Gradle (2.1) and IntelliJ (14.0.2) to play well. In particular, I imported a sample Gradle project containing a separate set of sources for integration tests in IntelliJ.

The project builds fine using Gradle on the command line, and I can successfully complete the integration tests. On the other hand, while working inside IntelliJ, I have two problems:

1) Compilation inside IntelliJ is not performed due to a dependency in the integration test with a third-party library (collections of collections), which is not allowed.

2) If I remove the dependency above and compile, I cannot run the integration test inside IntelliJ. The following error message appears:

The tests found do not include: [org.gradle.PersonIntegrationTest.canConstructAPersonWithAName]

The file structure is as follows:

src integration-test java resources main java resources test java resources build.gradle 

And build.gradle:

 apply plugin: 'java' repositories { mavenCentral() } sourceSets { integrationTest { java.srcDir file('src/integration-test/java') resources.srcDir file('src/integration-test/resources') } } dependencies { testCompile 'junit:junit:4.11' integrationTestCompile 'commons-collections:commons-collections:3.2' integrationTestCompile sourceSets.main.output integrationTestCompile configurations.testCompile integrationTestCompile sourceSets.test.output integrationTestRuntime configurations.testRuntime } task integrationTest(type: Test, dependsOn: jar) { testClassesDir = sourceSets.integrationTest.output.classesDir classpath = sourceSets.integrationTest.runtimeClasspath systemProperties['jar.path'] = jar.archivePath } check.dependsOn integrationTest 

Any ideas on how to make this work would be greatly appreciated.

A complete sample of the Gradle project is available in the Gradle distribution, under the / java / withIntegrationTests samples

+7
intellij-idea intellij-14 gradle
source share
1 answer

You need to tell IDEA to map the entries from your integrationTest configuration in your project as TEST dependencies. I am not sure whether to add source root directories. An important part:

 idea { module { //and some extra test source dirs testSourceDirs += file('some-extra-test-dir') generatedSourceDirs += file('some-extra-source-folder') scopes.TEST.plus += [ configurations.integrationTest ] } } 

More details are described at http://www.gradle.org/docs/current/dsl/org.gradle.plugins.ide.idea.model.IdeaModule.html


Edits to reflect Daniel's comments: generatedSourceDirs is Gradle 2.2+. To set up a test task, you will use a task, for example

 task integTest(type: Test) { description = 'Runs the integration tests.' group = 'verification' testClassesDir = sourceSets.integTest.output.classesDir classpath = sourceSets.integTest.runtimeClasspath reports.junitXml.destination = file("${project.testResultsDir}/$name") reports.html.destination = file("${project.reporting.baseDir}/$name") shouldRunAfter test } check.dependsOn integTest 
+7
source share

All Articles