I'm adding a cucumber 'component test' to my Springboot project. I'm using @SpringBootTest so the test shares the same JVM as the application (except the main class).
I have a separate source set for my cucumber test in build.gradle.kts -
val SourceSet.kotlin: SourceDirectorySet
get() = project.extensions.getByType<KotlinJvmProjectExtension>().sourceSets.getByName(name).kotlin
sourceSets {
create("cucumber") {
kotlin.srcDirs( "src/cucumber")
compileClasspath = sourceSets["main"].output configurations["testRuntimeClasspath"]
runtimeClasspath = output compileClasspath sourceSets["test"].runtimeClasspath
}
}
task<Test>("cucumber") {
description = "Runs the cucumber tests"
group = "verification"
testClassesDirs = sourceSets["cucumber"].output.classesDirs
classpath = sourceSets["cucumber"].runtimeClasspath
useJUnitPlatform()
}
My project source sets now look like this -
I want the test to be black box. So, I'd like to prevent my 'cucumber' source set from having access to any of the code in my 'main' source set.
I'm using Java 9 modules to try and achieve this, here is my 'cucumber' module-info.java -
open module at {
requires com.johncooper.reactiveKotlin;
requires ...
}
and here is my 'main' module-info.java -
module com.johncooper.reactiveKotlin {
requires spring.boot.autoconfigure;
requires ...
exports com.johncooper.reactiveKotlin;
}
I'm getting a compilation error when running my 'cucumber' test -
Task :compileCucumberKotlin FAILED e: Module com.johncooper.reactiveKotlin cannot be found in the module graph
I've tried putting the module-info.java files into a java root folder (suggested in another post) without success.
Does anybody have any insight?
CodePudding user response:
The solution is to avoid Java 9 modules and use Kotlin's own native module functionality! Here is the the documentation from the Kotlin team - https://kotlinlang.org/docs/visibility-modifiers.html#modules