Skip to content

Commit 84a9a2d

Browse files
authored
Pass javacArguments to Kapt
1 parent 82ec542 commit 84a9a2d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

core/src/main/kotlin/com/tschuchort/compiletesting/KotlinCompilation.kt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,34 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
350350
args.suppressMissingBuiltinsError = suppressMissingBuiltinsError
351351
}
352352

353+
private fun convertJavacArgumentsListToMap(options: List<String>): Map<String, String> {
354+
val result = mutableMapOf<String, String>()
355+
var i = 0
356+
357+
while (i < options.size) {
358+
val option = options[i]
359+
if (option.startsWith("-") || option.startsWith("--")) {
360+
// Check if the option contains an equal sign
361+
if (option.contains("=")) {
362+
val (key, value) = option.split("=", limit = 2)
363+
result[key] = value
364+
} else {
365+
// Check if the next element is a value for this option
366+
val value = if (i + 1 < options.size && !options[i + 1].startsWith("-")) {
367+
i++ // Increment the index to skip the value in the next iteration
368+
options[i]
369+
} else {
370+
""
371+
}
372+
result[option] = value
373+
}
374+
}
375+
i++
376+
}
377+
378+
return result
379+
}
380+
353381
/** Performs the 1st and 2nd compilation step to generate stubs and run annotation processors */
354382
private fun stubsAndApt(sourceFiles: List<Path>): ExitCode {
355383
if(annotationProcessors.isEmpty()) {
@@ -369,6 +397,8 @@ class KotlinCompilation : AbstractKotlinCompilation<K2JVMCompilerArguments>() {
369397

370398
it.mode = AptMode.STUBS_AND_APT
371399

400+
it.javacOptions.putAll(convertJavacArgumentsListToMap(javacArguments))
401+
372402
if (verbose)
373403
it.flags.addAll(KaptFlag.MAP_DIAGNOSTIC_LOCATIONS, KaptFlag.VERBOSE)
374404
}

0 commit comments

Comments
 (0)