diff --git a/README.md b/README.md index 320e986..8ac5445 100644 --- a/README.md +++ b/README.md @@ -57,15 +57,6 @@ internal object BuildConfig { > buildConfigField("FILE", file("aFile").relativeToOrSelf(projectDir)) // use this instead, for instance > ``` -> [!IMPORTANT] -> When using along with the Kotlin plugin, both needs to be loaded in the same classloader (declared in the same Gradle project, like the root one for instance) -> ```kotlin -> plugins { -> id("org.jetbrains.kotlin.jvm") apply false -> id("com.github.gmazzo.buildconfig") apply false -> } -> ``` - ## Usage in Groovy On your `build.gradle` add: ```groovy diff --git a/plugin/src/main/kotlin/com/github/gmazzo/buildconfig/internal/bindings/KotlinHandler.kt b/plugin/src/main/kotlin/com/github/gmazzo/buildconfig/internal/bindings/KotlinHandler.kt index 1c5b338..b6f122a 100644 --- a/plugin/src/main/kotlin/com/github/gmazzo/buildconfig/internal/bindings/KotlinHandler.kt +++ b/plugin/src/main/kotlin/com/github/gmazzo/buildconfig/internal/bindings/KotlinHandler.kt @@ -6,26 +6,31 @@ import com.github.gmazzo.buildconfig.generators.BuildConfigKotlinGenerator import org.gradle.api.Named import org.gradle.api.NamedDomainObjectContainer import org.gradle.api.Project -import org.gradle.kotlin.dsl.getByName -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet -import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSetContainer +import org.gradle.api.file.SourceDirectorySet internal class KotlinHandler( project: Project, private val extension: BuildConfigExtension -) : PluginBindingHandler { +) : PluginBindingHandler { // TODO should be KotlinSourceSet but fails on tests (but not from external project) - override val sourceSets = - project.extensions.getByName("kotlin").sourceSets + // project.extensions.getByName("kotlin").sourceSets + override val sourceSets = with(project.extensions.getByName("kotlin")) { + @Suppress("UNCHECKED_CAST") + javaClass.getMethod("getSourceSets") + .invoke(this) as NamedDomainObjectContainer + } - override fun nameOf(sourceSet: KotlinSourceSet): String = sourceSet.name + override fun nameOf(sourceSet: Named): String = sourceSet.name override fun onBind() { extension.generator.convention(BuildConfigKotlinGenerator()) } - override fun onSourceSetAdded(sourceSet: KotlinSourceSet, spec: BuildConfigSourceSet) { - sourceSet.kotlin.srcDir(spec) + // sourceSet.kotlin.srcDir(spec) + override fun onSourceSetAdded(sourceSet: Named, spec: BuildConfigSourceSet) { + (sourceSet.javaClass.getMethod("getKotlin") + .invoke(sourceSet) as SourceDirectorySet) + .srcDir(spec) } } diff --git a/plugin/src/main/kotlin/com/github/gmazzo/buildconfig/internal/bindings/KotlinMultiplatformHandler.kt b/plugin/src/main/kotlin/com/github/gmazzo/buildconfig/internal/bindings/KotlinMultiplatformHandler.kt index eebdf0b..cb69f80 100644 --- a/plugin/src/main/kotlin/com/github/gmazzo/buildconfig/internal/bindings/KotlinMultiplatformHandler.kt +++ b/plugin/src/main/kotlin/com/github/gmazzo/buildconfig/internal/bindings/KotlinMultiplatformHandler.kt @@ -1,13 +1,14 @@ package com.github.gmazzo.buildconfig.internal.bindings +import org.gradle.api.Named import org.gradle.api.tasks.SourceSet import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet internal class KotlinMultiplatformHandler( private val kotlinHandler: KotlinHandler -) : PluginBindingHandler by kotlinHandler { +) : PluginBindingHandler by kotlinHandler { - override fun nameOf(sourceSet: KotlinSourceSet) = when (val name = kotlinHandler.nameOf(sourceSet)) { + override fun nameOf(sourceSet: Named) = when (val name = kotlinHandler.nameOf(sourceSet)) { KotlinSourceSet.COMMON_MAIN_SOURCE_SET_NAME -> SourceSet.MAIN_SOURCE_SET_NAME KotlinSourceSet.COMMON_TEST_SOURCE_SET_NAME -> SourceSet.TEST_SOURCE_SET_NAME else -> name