@@ -9,17 +9,29 @@ import java.util.Properties
9
9
10
10
@Suppress(" unused" )
11
11
class ConvenienceSchemaGeneratorPlugin : Plugin <Project > {
12
+ companion object {
13
+ /* *
14
+ * (boolean, default `true`) whether to add KSP plugin
15
+ */
16
+ const val PROP_ADD_KSP = " kotlin.dataframe.add.ksp"
17
+
18
+ /* *
19
+ * (string, default `null`) comma-delimited list of configurations to add KSP processing to.
20
+ * Defaults to guessing configurations based on which kotlin plugin is applied (jvm or multiplatform)
21
+ */
22
+ const val PROP_KSP_CONFIGS = " kotlin.dataframe.ksp.configs"
23
+ }
24
+
12
25
override fun apply (target : Project ) {
13
- val name = " kotlin.dataframe.add.ksp"
14
- val property = target.findProperty(name)?.toString()
26
+ val property = target.findProperty(PROP_ADD_KSP )?.toString()
15
27
var addKsp = true
16
28
17
29
if (property != null ) {
18
30
if (property.equals(" true" , ignoreCase = true ) || property.equals(" false" , ignoreCase = true )) {
19
31
addKsp = property.toBoolean()
20
32
} else {
21
33
target.logger.warn(
22
- " Invalid value '$property ' for '$name ' property. Defaulting to '$addKsp '. Please use 'true' or 'false'." ,
34
+ " Invalid value '$property ' for '$PROP_ADD_KSP ' property. Defaulting to '$addKsp '. Please use 'true' or 'false'." ,
23
35
)
24
36
}
25
37
}
@@ -32,7 +44,7 @@ class ConvenienceSchemaGeneratorPlugin : Plugin<Project> {
32
44
// configure it to depend on symbol-processor-all
33
45
target.plugins.whenPluginAdded {
34
46
if (" com.google.devtools.ksp" in this .javaClass.packageName) {
35
- val isMultiplatform =
47
+ val isMultiplatform by lazy {
36
48
when {
37
49
target.plugins.hasPlugin(" org.jetbrains.kotlin.jvm" ) -> false
38
50
@@ -45,29 +57,28 @@ class ConvenienceSchemaGeneratorPlugin : Plugin<Project> {
45
57
false
46
58
}
47
59
}
48
- val mainKspCfg = if (isMultiplatform) " kspJvm" else " ksp"
49
- val testKspCfg = if (isMultiplatform) " kspJvmTest" else " kspTest"
50
- try {
51
- target.configurations.getByName(mainKspCfg).dependencies.add(
52
- target.dependencies.create(
53
- " org.jetbrains.kotlinx.dataframe:symbol-processor-all:$preprocessorVersion " ,
54
- ),
55
- )
56
- } catch (e: UnknownConfigurationException ) {
57
- target.logger.warn(
58
- " Configuration '$mainKspCfg ' not found. Please make sure the KSP plugin is applied." ,
59
- )
60
60
}
61
- try {
62
- target.configurations.getByName(testKspCfg).dependencies.add(
63
- target.dependencies.create(
64
- " org.jetbrains.kotlinx.dataframe:symbol-processor-all:$preprocessorVersion " ,
65
- ),
66
- )
67
- } catch (e: UnknownConfigurationException ) {
68
- target.logger.warn(
69
- " Configuration '$testKspCfg ' not found. Please make sure the KSP plugin is applied." ,
70
- )
61
+ val overriddenConfigs = target.findProperty(PROP_KSP_CONFIGS )
62
+ ?.let { (it as String ) }
63
+ ?.split(" ," )
64
+ ?.map { it.trim() }
65
+ val configs = when {
66
+ overriddenConfigs != null -> overriddenConfigs
67
+ isMultiplatform -> listOf (" kspJvm" , " kspJvmTest" )
68
+ else -> listOf (" ksp" , " kspTest" )
69
+ }
70
+ configs.forEach { cfg ->
71
+ try {
72
+ target.configurations.getByName(cfg).dependencies.add(
73
+ target.dependencies.create(
74
+ " org.jetbrains.kotlinx.dataframe:symbol-processor-all:$preprocessorVersion " ,
75
+ ),
76
+ )
77
+ } catch (e: UnknownConfigurationException ) {
78
+ target.logger.warn(
79
+ " Configuration '$cfg ' not found. Please make sure the KSP plugin is applied." ,
80
+ )
81
+ }
71
82
}
72
83
target.logger.info(" Added DataFrame dependency to the KSP plugin." )
73
84
target.extensions.getByType<KspExtension >().arg(
0 commit comments