Dears, in my kotlin (JVM) project, I'm following t...
# community-support
j
Dears, in my kotlin (JVM) project, I'm following this guide: https://docs.gradle.org/current/userguide/jvm_test_suite_plugin.html#sec:declare_an_additional_test_suite to add a test suite (and associated SourceSet) for my integration tests. Everything works well until it tries to compile an IT that needs to access an
internal
class, then I get this error:
Cannot access 'UserCreationContext': it is internal in 'UserCreateService'
According to Kotlin's doc, this behaviour is normal, only SourceSet
test
can access internal members of SourceSet
main
https://kotlinlang.org/docs/visibility-modifiers.html#modules This is what I tried so far:
Copy code
testing {
    suites {
        val test by getting(JvmTestSuite::class) {
            useJUnitJupiter() // JUnit 5 only
        }
        register<JvmTestSuite>("integrationTest") {
            testType = TestSuiteType.INTEGRATION_TEST
            dependencies {
                implementation(project())
            }
            sources {
                kotlin {
                    srcDirs("src/integration-test/kotlin")
                    // ITs depends on Factories that are in UTs
                    compileClasspath += sourceSets.test.get().output
                    runtimeClasspath += sourceSets.test.get().output
                }
            }
        }
    }
}
// ITs inherit classpath of UT (transitively inherits classpath of main)
val integrationTestImplementation: Configuration by configurations.getting {
    extendsFrom(configurations.testImplementation.get())
}
Thanks for your help 🙏
t
You need to declare your Kotlin targets as "friends" for the integrationTest one to be able to access
internal
members of the main one. I, for one, use the following to allow it: https://github.com/tbroyer/gradle-errorprone-plugin/blob/2edcdf943bf4c6dd8b539446dbd1e1f3aff9087d/build.gradle.kts#L77-L80
Copy code
// associate with main Kotlin compilation to access internal constants
kotlin.target.compilations.named(name) {
    associateWith(kotlin.target.compilations["main"])
}
🙌 1
j
Thanks, it works perfectly!