4

I am trying to add another module to my Kotlin project specifically for integration tests - living alongside the standard test module creating by the kotlin plugin. Here is my current configuration to add the sourceset:

sourceSets {
    testIntegration {
        java.srcDir 'src/testIntegration/java'
        kotlin.srcDir 'src/testIntegration/kotlin'
        resources.srcDir 'src/testIntegration/resources'
        compileClasspath += main.output
        runtimeClasspath += main.output
    }
}

configurations {
    provided
    testCompile.extendsFrom provided
    testIntegrationCompile.extendsFrom testCompile
    testIntegrationRuntime.extendsFrom testRuntime
}

task testIntegration(type: Test) {
    testClassesDirs = sourceSets.testIntegration.output.classesDirs
    classpath = sourceSets.testIntegration.runtimeClasspath
}

This seems to work, however IntelliJ does not pick up the new source set as a test module. I can manually mark it, but it resets every time Gradle runs. This also means that Intellij fills in the Output Path and not the Test Output Path fields in the project structure settings.

To fix that the below configuration works:

apply plugin: 'idea'

idea {
    module {
        testSourceDirs += project.sourceSets.testIntegration.java.srcDirs
        testSourceDirs += project.sourceSets.testIntegration.kotlin.srcDirs
        testSourceDirs += project.sourceSets.testIntegration.resources.srcDirs
    }
}

However, this seems to instruct IntelliJ that the Test Output Path is \out\test\classes which is the same as the standard 'test' module and causes conflict issues. I want it to keep the output path as the original \out\testIntegration\classes which would have otherwise been used.

Is there any way to instruct IntelliJ to pick up this new test source set correctly and fill in the right output path?

Ian
  • 73
  • 1
  • 4

1 Answers1

0

If you'd like to configure the idea gradle plugin with your custom test sourceSets in a kotlin gradle build script you can do it like that:

val testIntegrationSrcDirName = "testIntegration"

sourceSets {
   ...
    
   create(testIntegrationSrcDirName) {
            compileClasspath += sourceSets.main.get().output + sourceSets.test.get().output // take also unit test source and resources
            runtimeClasspath += sourceSets.main.get().output + sourceSets.test.get().output // take also unit test source and resources
   }
}
    
...

idea {
    module {
        testSourceDirs = testSourceDirs + sourceSets[testIntegrationSrcDirName].allSource.srcDirs
    }
}

val testIntegrationImplementation: Configuration by configurations.getting {
    extendsFrom(configurations.implementation.get())
}
configurations["${testIntegrationSrcDirName}RuntimeOnly"].extendsFrom(configurations.runtimeOnly.get())
...