Invoking gradlew from java process

Hi folks, I’m writing some automation for our CI/CD that bootstraps a project folder and includes gradle resources (folder, gradlew, properties and build). The goal is to copy some protobuffer files and then just invoke the build to generate the class files.

So far all is working when generating the project I end up with resources on the right places. And from a shell, ./gradlew build just works.

However when I execute it from my java code, the Process hangs and never terminates. I’m assuming its because the daemon is running on a different PID (tried to force no daemon but got "To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: https://docs.gradle.org/6.7-rc-5/userguide/gradle_daemon.html."). The wrapper is set to use gradle-6.7-rc-5

And the code to execute gradlew is the snippet below:

for(File protoFolder : inputDir.listFiles((dir, name) -> dir.isDirectory())) {
try {
projectGenerator.visit(protoFolder);
if(!CollectionUtils.isEmpty(parameters)) {
List commands = new LinkedList<>();
commands.add("./gradlew");
commands.add("-Dorg.gradle.daemon.debug=true");
commands.addAll(parameters);
ProcessBuilder processBuilder = new ProcessBuilder(commands);
processBuilder.directory(new File(protoFolder, “java-project”));
Process process = processBuilder.start();
InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
int exitCode = process.waitFor();
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}

Any ideas? Thank you

You should use the tooling API