5

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?

1 Answer 1

0

You can cheat it by using @Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") annotation above your internal usage. Although, it will be deprecated in the future & is (obviously) unsafe.

Not the answer you're looking for? Browse other questions tagged or ask your own question.