I have integration and system test source sets and...
# gradle
e
I have integration and system test source sets and I’ve marked the related folders in IntelliJ as test sources root. Whenever I do a Gradle sync, it changes back to sources root. How can I define in Gradle that the root folder is test sources root? Here’s how I define the sourceSet and test task for integration tests:
Copy code
// custom task type to be able to create custom environment variables here
abstract class IntegrationTest : Test()

val integrationTest: SourceSet by sourceSets.creating {
    compileClasspath += sourceSets.main.get().output
    runtimeClasspath += sourceSets.main.get().output
}

configurations[integrationTest.implementationConfigurationName].extendsFrom(configurations.testImplementation.get())
configurations[integrationTest.runtimeOnlyConfigurationName].extendsFrom(configurations.runtimeOnly.get())

val integrationTestTask = tasks.register<IntegrationTest>("integrationTest") {
    description = "Runs integration tests."
    group = "verification"
    testClassesDirs = sourceSets["integrationTest"].output.classesDirs
    classpath = sourceSets["integrationTest"].runtimeClasspath
}

tasks.withType<IntegrationTest> {
    val envName = "local"

    environment(
        mapOf(
            "KEY" to "myTestValue"
        )
    )
}
e
doesn’t seem to work for some reason
I did this:
Copy code
plugins {
   ...
   id("java")
   id("idea")
}

dependencies {
   ...
}

idea {
    module {
        testSourceDirs.add(file("myExistingPathToTheFolder"))
    }
}

...
allProjects {
   apply(plugin = "idea")
}
ok, just managed to figure out
Copy code
val SourceSet.kotlin: SourceDirectorySet
    get() = project.extensions.getByType<org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension>().sourceSets.getByName(name).kotlin

testSourceDirs = testSourceDirs.plus(sourceSets["integrationTest"].kotlin.srcDirs)
v
Starting with 7.3 using
add
will work. That it didn't work is a bug that a PR of me fixed for 7.3.
👍 1
e
we are using 7.2
thanks for the heads up!
v
Of course, 7.3 is not released yet. 😄