Home > front end >  Cannot run gradlew.bat from project sub folder
Cannot run gradlew.bat from project sub folder

Time:05-30

I have below project struture

MyProject
    projA
    projB
        build.gradle
gradlew.bat
build.gradle
gradlew
settings.gradle

I have below task in MyProject/projB/build.gradle

def process;
task bootRunStartDaemon() {
    doFirst {

        println("Starting application it profile")

        ProcessBuilder builder = new ProcessBuilder("./gradlew.bat", "bootRun", "--args='--spring.profiles.active=it'")
        builder.redirectErrorStream(true)
        builder.directory(projectDir)
        process = builder.start()

    }
}

However when I run > gradlew bootRunStartDaemon from the root directory I get below error

Caused by: org.gradle.api.UncheckedIOException: java.io.IOException: Cannot run program "./gradlew.bat" (in directory "MyProject\projB"): CreateProcess error=2, The system cannot find the file specified
        at org.gradle.internal.UncheckedException.throwAsUncheckedException(UncheckedException.java:62)

I have below in settings.gradle

....
rootProject.name = "MyProject"
include "projA", "projB"

CodePudding user response:

I mamaged to run gradlew.bat by adding the path as below. Because gradlew.bat scripts only exists under the root folder.

ProcessBuilder builder = new ProcessBuilder(projectDir.toString().replace("projB","")    gradleCommand, "bootRun", "--args='--spring.profiles.active=it'")
  • Related