How can I run appRunWar in a port other than the one defined in the build.gradle

928 Views Asked by At

I' having issues while trying to change the port for Gretty as indicated in the Gretty documentation.

Gradle appRunWar -PhttpPort=8888 

The only way it works is by changing the build.gradle gretty block

gretty {
    http = 8888
    contextPath = '/'
}
1

There are 1 best solutions below

0
On BEST ANSWER

I found the solution after searching the Gretty Possible Running Build in Different Ports Github repository.

All you need to do is change the build.gradle file as follows

gretty {
    httpPort = project.hasProperty("httpPort") ? project.httpPort as int : 8080
    contextPath = '/'
}

Another way to do this is by adding the following

gradle.taskGraph.whenReady {
    graph ->
        if (project.hasProperty("httpPort")) {
            gretty.httpPort = httpPort as int
        }
}

Both solutions will work by passing property arguments to the guild file

 gradle -PhttpPort=8888