Skip to content

Commit 6f0baf8

Browse files
committed
fixes case where ksp is disabled from the plugin but still needs to be configured
1 parent 739133b commit 6f0baf8

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

plugins/dataframe-gradle-plugin/src/main/kotlin/org/jetbrains/dataframe/gradle/ConvenienceSchemaGeneratorPlugin.kt

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package org.jetbrains.dataframe.gradle
33
import com.google.devtools.ksp.gradle.KspExtension
44
import org.gradle.api.Plugin
55
import org.gradle.api.Project
6+
import org.gradle.api.artifacts.UnknownConfigurationException
67
import org.gradle.kotlin.dsl.findByType
78
import java.util.*
89

@@ -20,9 +21,33 @@ class ConvenienceSchemaGeneratorPlugin : Plugin<Project> {
2021
target.logger.warn("Invalid value '$property' for '$name' property. Defaulting to '$addKsp'. Please use 'true' or 'false'.")
2122
}
2223
}
24+
25+
val properties = Properties()
26+
properties.load(javaClass.getResourceAsStream("plugin.properties"))
27+
val preprocessorVersion = properties.getProperty("PREPROCESSOR_VERSION")
28+
29+
// regardless whether we add KSP or the user adds it, when it's added,
30+
// configure it to depend on symbol-processor-all
31+
target.plugins.whenPluginAdded {
32+
if ("com.google.devtools.ksp" in this.javaClass.packageName) {
33+
target.configurations.getByName("ksp").dependencies.add(
34+
target.dependencies.create("org.jetbrains.kotlinx.dataframe:symbol-processor-all:$preprocessorVersion")
35+
)
36+
target.logger.info("Added DataFrame dependency to the KSP plugin.")
37+
}
38+
}
39+
2340
if (addKsp) {
24-
target.plugins.apply(KspPluginApplier::class.java)
41+
target.plugins.apply(KspPluginApplierAndConfigurer::class.java)
42+
} else {
43+
target.logger.warn(
44+
"Plugin 'org.jetbrains.kotlinx.dataframe' comes bundled with its own version of KSP which is " +
45+
"currently disabled as 'kotlin.dataframe.add.ksp' is set to 'false' in a 'properties' file. " +
46+
"Either set 'kotlin.dataframe.add.ksp' to 'true' or add the plugin 'com.google.devtools.ksp' " +
47+
"manually."
48+
)
2549
}
50+
2651
target.afterEvaluate {
2752
target.extensions.findByType<KspExtension>()?.arg("dataframe.resolutionDir", target.projectDir.absolutePath)
2853
}
@@ -38,14 +63,13 @@ class DeprecatingSchemaGeneratorPlugin : Plugin<Project> {
3863
}
3964
}
4065

41-
internal class KspPluginApplier : Plugin<Project> {
66+
/**
67+
* Applies and configures the KSP plugin in the target project.
68+
*/
69+
internal class KspPluginApplierAndConfigurer : Plugin<Project> {
4270
override fun apply(target: Project) {
4371
val properties = Properties()
4472
properties.load(javaClass.getResourceAsStream("plugin.properties"))
45-
val preprocessorVersion = properties.getProperty("PREPROCESSOR_VERSION")
4673
target.plugins.apply("com.google.devtools.ksp")
47-
target.configurations.getByName("ksp").dependencies.add(
48-
target.dependencies.create("org.jetbrains.kotlinx.dataframe:symbol-processor-all:$preprocessorVersion")
49-
)
5074
}
5175
}

0 commit comments

Comments
 (0)