diff --git a/multisrc/build.gradle.kts b/multisrc/build.gradle.kts index c6253bc21..12cbc3004 100644 --- a/multisrc/build.gradle.kts +++ b/multisrc/build.gradle.kts @@ -1,3 +1,6 @@ +import java.io.BufferedReader +import java.io.InputStreamReader + plugins { id("com.android.library") kotlin("android") @@ -24,22 +27,37 @@ tasks { val generateExtensions by registering { doLast { val isWindows = System.getProperty("os.name").toString().toLowerCase().contains("win") - val classPath = (configurations.debugCompileOnly.get().asFileTree.toList() + + var classPath = (configurations.debugCompileOnly.get().asFileTree.toList() + listOf( configurations.androidApis.get().asFileTree.first().absolutePath, // android.jar path "$projectDir/build/intermediates/aar_main_jar/debug/classes.jar" // jar made from this module )) .joinToString(if (isWindows) ";" else ":") - val javaPath = "${System.getProperty("java.home")}/bin/java" + + var javaPath = "${System.getProperty("java.home")}/bin/java" val mainClass = "generator.GeneratorMainKt" // Main class we want to execute - val javaCommand = if (isWindows) { - "\"$javaPath\" -classpath $classPath $mainClass".replace("/", "\\") - } else { - "$javaPath -classpath $classPath $mainClass" + if (isWindows) { + classPath = classPath.replace("/", "\\") + javaPath = javaPath.replace("/", "\\") } - val javaProcess = Runtime.getRuntime().exec(javaCommand) + + val javaProcess = ProcessBuilder() + .directory(null).command(javaPath, "-classpath", classPath, mainClass) + .redirectErrorStream(true).start() + + val inputStreamReader = InputStreamReader(javaProcess.inputStream) + val bufferedReader = BufferedReader(inputStreamReader) + + var s: String? + while (bufferedReader.readLine().also { s = it } != null) { + logger.info(s) + } + + bufferedReader.close() + inputStreamReader.close() + val exitCode = javaProcess.waitFor() if (exitCode != 0) { throw Exception("Java process failed with exit code: $exitCode")