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:"). 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 {
if(!CollectionUtils.isEmpty(parameters)) {
List commands = new LinkedList<>();
ProcessBuilder processBuilder = new ProcessBuilder(commands); 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) {
int exitCode = process.waitFor();
} catch (IOException | InterruptedException e) {

Any ideas? Thank you

You should use the tooling API