@@ -3,7 +3,8 @@ package org.jetbrains.dataframe.gradle
3
3
import com.google.devtools.ksp.gradle.KspExtension
4
4
import org.gradle.api.Plugin
5
5
import org.gradle.api.Project
6
- import org.gradle.kotlin.dsl.findByType
6
+ import org.gradle.api.artifacts.UnknownConfigurationException
7
+ import org.gradle.kotlin.dsl.getByType
7
8
import java.util.*
8
9
9
10
@Suppress(" unused" )
@@ -20,11 +21,43 @@ class ConvenienceSchemaGeneratorPlugin : Plugin<Project> {
20
21
target.logger.warn(" Invalid value '$property ' for '$name ' property. Defaulting to '$addKsp '. Please use 'true' or 'false'." )
21
22
}
22
23
}
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
+ try {
34
+ target.configurations.getByName(" ksp" ).dependencies.add(
35
+ target.dependencies.create(" org.jetbrains.kotlinx.dataframe:symbol-processor-all:$preprocessorVersion " )
36
+ )
37
+ } catch (e: UnknownConfigurationException ) {
38
+ target.logger.warn(" Configuration 'ksp' not found. Please make sure the KSP plugin is applied." )
39
+ }
40
+ try {
41
+ target.configurations.getByName(" kspTest" ).dependencies.add(
42
+ target.dependencies.create(" org.jetbrains.kotlinx.dataframe:symbol-processor-all:$preprocessorVersion " )
43
+ )
44
+ } catch (e: UnknownConfigurationException ) {
45
+ target.logger.warn(" Configuration 'kspTest' not found. Please make sure the KSP plugin is applied." )
46
+ }
47
+ target.logger.info(" Added DataFrame dependency to the KSP plugin." )
48
+ target.extensions.getByType<KspExtension >().arg(" dataframe.resolutionDir" , target.projectDir.absolutePath)
49
+ }
50
+ }
51
+
23
52
if (addKsp) {
24
53
target.plugins.apply (KspPluginApplier ::class .java)
25
- }
26
- target.afterEvaluate {
27
- target.extensions.findByType<KspExtension >()?.arg(" dataframe.resolutionDir" , target.projectDir.absolutePath)
54
+ } else {
55
+ target.logger.warn(
56
+ " Plugin 'org.jetbrains.kotlinx.dataframe' comes bundled with its own version of KSP which is " +
57
+ " currently disabled as 'kotlin.dataframe.add.ksp' is set to 'false' in a 'properties' file. " +
58
+ " Either set 'kotlin.dataframe.add.ksp' to 'true' or add the plugin 'com.google.devtools.ksp' " +
59
+ " manually."
60
+ )
28
61
}
29
62
target.plugins.apply (SchemaGeneratorPlugin ::class .java)
30
63
}
@@ -38,14 +71,13 @@ class DeprecatingSchemaGeneratorPlugin : Plugin<Project> {
38
71
}
39
72
}
40
73
74
+ /* *
75
+ * Applies the KSP plugin in the target project.
76
+ */
41
77
internal class KspPluginApplier : Plugin <Project > {
42
78
override fun apply (target : Project ) {
43
79
val properties = Properties ()
44
80
properties.load(javaClass.getResourceAsStream(" plugin.properties" ))
45
- val preprocessorVersion = properties.getProperty(" PREPROCESSOR_VERSION" )
46
81
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
- )
50
82
}
51
83
}
0 commit comments