Gradle Kotlin plugin: Associate additional source sets with test

So I am using multiple source sets in a single gradle module to benefit from the internal modifier: My project consists of multiple components, and I want to hide internal code from the component’s API. I see no strong reason to use different gradle modules though, since all components will be part of the same application, it is not like a library, that I will later depend on.

So I added multiple source sets, because to my understanding, internal is then restricted to each source set, thereby hiding all component-internal code inside the source set, and exposing only the public API for other components.

sourceSets {
    database {
        dependencies { ... }
    }
    main { 
        compileClasspath += sourceSets.database.runtimeClasspath
    }
}

However, now I also want to write unit tests for the application. I don’t really care whether I have a unit test source set for each production source set, or one common source set, but I guess multiple is the way to go, since I have to somehow treat one production source set and one test source set as a singular module to access internal members.
If I have only one module, obviously I can access internal methods without problems, because the default configuration for the test module allows me to. But how do I create those test source sets? I neither know how to mark a source set as test sources, nor how to join a production source set, and a test source set into a singular module, so the test sources can access internal members.

1 Like