I am writing a custom Gradle plugin to configure our common Kotlin build settings, which includes creating an integrationTest sourceSet. I created a simple Kotlin project to ensure that I had everything correct in a build.gradle.kts file before translating it into the custom plugin project. I am getting a compilation error in the plugin:
"Unresolved reference: sourceSets"
I think that the issue may be because I am trying to access the sourceSet in the plugin in an incorrect manner. I saw some references online about using
the<SourceSetContainer>()
rather than how I am accessing the sets, below. However, I cannot seem to get this to work in the custom plugin...compilation error.
I'd appreciate your help!
class CscKotlinPlugin: Plugin<Project> {
private lateinit var javaPluginExtension: JavaPluginExtension
override fun apply(project: Project) {
with(project) {
javaPluginExtension = project.extensions.getByType(JavaPluginExtension::class.java)
configureBuild()
. . .
private fun Project.configureBuild() {
val implementation = configurations.getByName("implementation")
val integrationTestImplementation =
configurations.getByName("integrationTestImplementation").also { it.extendsFrom(implementation) }
val runtimeOnly = configurations.getByName("runtimeOnly")
val integrationTestRuntimeOnly =
configurations.getByName("integrationTestRuntimeOnly").also { it.extendsFrom(runtimeOnly) }
with(javaPluginExtension) {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
withJavadocJar()
withSourcesJar()
with(sourceSets) {
val main = getByName("main").let { main ->
create("integrationTest") { sourceSet ->
sourceSet.compileClasspath += main.output
sourceSet.runtimeClasspath += main.output
sourceSet.resources.srcDir("src/integrationTest/resources")
sourceSet.java { sourceDirectorySet ->
sourceDirectorySet.srcDir("src/integrationTest/java")
sourceDirectorySet.srcDir("src/integrationTest/kotlin")
}
}
}
val test = findByName("test")
}
}
}

