Is it possible to indicate to IntelliJ, via Gradle...
# intellij
j
Is it possible to indicate to IntelliJ, via Gradle, that a source directory is for tests? For example,
test/kotlin
is green, meanwhile
functionalTest/kotlin
is blue.
s
how are you adding the
functionalTest
source set? idk if IJ detects whether it depends on
test
or whatever you can use
Mark As > Test Sources
in the UI but that wouldn't persist
r
I use the following Gradle config to mark an
integrationTest
directory (from the sourceset
integrationTestSourceSet
) as test sources, by using the
idea
plugin:
Copy code
plugins {
    // ... other plugins

    idea
}

idea {
    module {
        testSources.from(integrationTestSourceSet.allSource.sourceDirectories)
    }
}
j
I am adding it so
Copy code
sourceSets.register("functionalTest")
@Riccardo Lippolis without that plugin is not possible right? I am not using it yet as it is not compatible with project isolation
r
I don't think so. It's an IntelliJ-specific setting, so it has to be configured in the IntelliJ configuration. If you want to do that from the Gradle build file, the
idea
plugin is suitable for that. So if you want to keep the Gradle file independent from IntelliJ-specific stuff, that's not an option 😅
e
if you use the jvm-test-suite plugin you can create another test suite and it should be picked up correctly IIRC..
j
that plugin is not compatible with KMP, right?
e
I suppose not, considering it's naming, but can't say for sure 😁
j
@Riccardo Lippolis as they are doing that automatically for
test
, I would expect something similar for other regex like
fooTest
or
testFoo
r
maybe this works for you: https://www.jetbrains.com/help/idea/testing.html#gradle-use-custom-test-root it looks like it's an array, so maybe you can supply multiple source directories there (I haven't tried it)
j
yeah I could use this one, but I would have to do that on each project, I would keep it as blue until idea plugin is fixed
r
but if you define it in the Gradle build file, you would still have to do that on each project, right? I mean, regardless of whether you're using the
idea
plugin
j
I don't follow you 🤔, they are already picked by intellij via gradle, the only problem is they are not colored with green in the editor, but I can run them with right click run tests for example
so intellij knows it is a source set and it contains tests and it is able to run them, but it is not marked with the green color, but you can run all test in
main
too
r
so, your original question was that you want to make the
functionalTest/kotlin
directory shown as a test sources dir in IntelliJ (make it green). So I suggested the
idea
plugin. So then you asked if it was possible without the plugin, so I sent you the link to the IDEA documentation describing a way that would not involve the plugin, something like this:
Copy code
sourceSets {
    test {
        kotlin {
            srcDirs("src/test/kotlin", "src/functionalTest/kotlin")
        }
    }
}
you then said "yeah I could use this one, but I would have to do that on each project", which is the point where I lost you (and you lost me as well, probably) 😛