Flip Gradle plugin kotlin_module names

Now common SourceSet output will have '_common' suffix, while all
variants will have the same name - '<module-name>.kotlin_module'.

This change is required for KSP as short-term workaround, as they
are using some internal properties/methods, which was mangled before
this change and hard to access in different variants.

^KT-52138 Fixed
This commit is contained in:
Yahor Berdnikau
2022-04-21 18:12:44 +02:00
committed by Space
parent 204bc4ca95
commit 5450367e39
2 changed files with 16 additions and 14 deletions
+15 -13
View File
@@ -128,6 +128,14 @@ fun Project.createGradleCommonSourceSet(): SourceSet {
}
}
// Common outputs will also produce '${project.name}.kotlin_module' file, so we need to avoid
// files clash
tasks.named<KotlinCompile>("compile${commonSourceSet.name.capitalize()}Kotlin") {
kotlinOptions {
moduleName = "${this@createGradleCommonSourceSet.name}_${commonSourceSet.name}"
}
}
return commonSourceSet
}
@@ -205,19 +213,6 @@ fun Project.wireGradleVariantToCommonGradleVariant(
getByName(wireSourceSet.name).associateWith(getByName(commonSourceSet.name))
}
// Common outputs will also produce '${project.name}.kotlin_module' file, so we need to avoid
// files clash
val compileTaskName = if (wireSourceSet.name == SourceSet.MAIN_SOURCE_SET_NAME) {
"compileKotlin"
} else {
"compile${wireSourceSet.name.capitalize()}Kotlin"
}
tasks.named<KotlinCompile>(compileTaskName) {
kotlinOptions {
moduleName = "${this@wireGradleVariantToCommonGradleVariant.name}_${wireSourceSet.name}"
}
}
configurations[wireSourceSet.apiConfigurationName].extendsFrom(
configurations[commonSourceSet.apiConfigurationName]
)
@@ -403,6 +398,13 @@ fun Project.createGradlePluginVariant(
}
}
// KT-52138: Make module name the same for all variants, so KSP could access internal methods/properties
tasks.named<KotlinCompile>("compile${variantSourceSet.name.capitalize()}Kotlin") {
kotlinOptions {
moduleName = this@createGradlePluginVariant.name
}
}
dependencies {
variantSourceSet.compileOnlyConfigurationName(kotlinStdlib())
variantSourceSet.compileOnlyConfigurationName("dev.gradleplugins:gradle-api:${variant.gradleApiVersion}")
@@ -100,7 +100,7 @@ class UpToDateIT : KGPBaseTest() {
val originalPaths get() = originalCompilerCp.map { it.replace("\\", "/") }.joinToString(", ") { "'$it'" }
override fun initProject(project: TestProject) = with(project) {
val pluginSuffix = "kotlin_gradle_plugin"
val pluginSuffix = "kotlin_gradle_plugin_common"
buildGradle.appendText(
"\nafterEvaluate { println 'compiler_cp=' + compileKotlin.getDefaultCompilerClasspath\$$pluginSuffix().toList() }"
)