I have a Kotlin project that uses Gradle for building/testing. In Kotlin you can mark dependencies as internal
, for example:
internal class MyClass : MyInterface
Now, I also want to run some integration tests separated from the normal test
task in Gradle, so I modified my build.gradle as follows:
sourceSets {
testIntegration {
compileClasspath = files(main.output, project.configurations.testCompileClasspath)
runtimeClasspath = files(testIntegration.output, main.output, project.configurations.testRuntimeClasspath)
}
}
task testIntegration(type: Test) {
group = "Verification"
description = "Integration tests"
testClassesDirs = sourceSets.testIntegration.output.classesDirs
classpath = sourceSets.testIntegration.runtimeClasspath
useTestNG()
}
It works fine except if I want to access the internal declaration:
// In my integration tests
val instance = factory.buildInstance()
assertTrue(instance is MyClass) // Compilation fails in this line because `MyClass` is internal
Going through the Kotlin documentation it mentions:
a Gradle source set (with the exception that the test source set can access the internal declarations of main);
How do I tell Gradle that the new testIntegration
source set should also be able to access internal
declarations from the main
source set?