@@ -34,6 +34,16 @@ var KotlinCompilation.symbolProcessors: List<SymbolProcessor>
34
34
val KotlinCompilation .kspSourcesDir: File
35
35
get() = kspWorkingDir.resolve(" sources" )
36
36
37
+ /* *
38
+ * Arbitrary arguments to be passed to ksp
39
+ */
40
+ var KotlinCompilation .kspArgs: MutableMap <String , String >
41
+ get() = getKspRegistrar().options
42
+ set(value) {
43
+ val registrar = getKspRegistrar()
44
+ registrar.options = value
45
+ }
46
+
37
47
private val KotlinCompilation .kspJavaSourceDir: File
38
48
get() = kspSourcesDir.resolve(" java" )
39
49
@@ -42,6 +52,7 @@ private val KotlinCompilation.kspKotlinSourceDir: File
42
52
43
53
private val KotlinCompilation .kspResourceDir: File
44
54
get() = kspSourcesDir.resolve(" resource" )
55
+
45
56
/* *
46
57
* The working directory for KSP
47
58
*/
@@ -80,11 +91,16 @@ private class KspCompileTestingComponentRegistrar(
80
91
private val compilation : KotlinCompilation
81
92
) : ComponentRegistrar {
82
93
var processors = emptyList<SymbolProcessor >()
94
+
95
+ var options: MutableMap <String , String > = mutableMapOf ()
96
+
83
97
override fun registerProjectComponents (project : MockProject , configuration : CompilerConfiguration ) {
84
98
if (processors.isEmpty()) {
85
99
return
86
100
}
87
101
val options = KspOptions .Builder ().apply {
102
+ this .processingOptions.putAll(compilation.kspArgs)
103
+
88
104
this .classOutputDir = compilation.kspClassesDir.also {
89
105
it.deleteRecursively()
90
106
it.mkdirs()
@@ -103,9 +119,11 @@ private class KspCompileTestingComponentRegistrar(
103
119
}
104
120
}.build()
105
121
// TODO: replace with KotlinCompilation.internalMessageStream
106
- val registrar = KspTestExtension (options, processors, MessageCollectorBasedKSPLogger (
122
+ val registrar = KspTestExtension (
123
+ options, processors, MessageCollectorBasedKSPLogger (
107
124
PrintingMessageCollector (System .err, MessageRenderer .GRADLE_STYLE , compilation.verbose)
108
- ))
125
+ )
126
+ )
109
127
AnalysisHandlerExtension .registerExtension(project, registrar)
110
128
}
111
129
}
0 commit comments