in src/main/kotlin/io/bazel/kotlin/builder/tasks/jvm/JDepsGenerator.kt [44:77]
fun generateJDeps(command: JvmCompilationTask) {
val jdepsContent =
if (command.inputs.classpathList.isEmpty()) {
emptyJdeps(command.info.label)
} else {
ByteArrayOutputStream().use { out ->
PrintWriter(out).use { writer ->
val joinedClasspath = command.inputs.joinedClasspath
val version = System.getProperty("java.version").majorJavaVersion()
val multiRelease =
if (version < 9) arrayOf() else arrayOf("--multi-release", "base")
val javaClassDir = command.directories.javaClasses
val args = multiRelease + arrayOf("-R", "-summary", "-cp", joinedClasspath, javaClassDir)
val res = invoker.run(args, writer)
out.toByteArray().inputStream().bufferedReader().readLines().let {
if (res != 0) {
throw CompilationStatusException("could not run jdeps tool", res, it)
} else try {
JdepsParser.parse(
command.info.label,
javaClassDir,
command.inputs.directDependenciesList,
it,
isKotlinImplicit
)
} catch (e: Exception) {
throw CompilationException("error reading or parsing jdeps file", e.rootCause)
}
}
}
}
}
writeJdeps(command.outputs.javaJdeps, jdepsContent)
}