Search code examples
javagretty

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


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 = '/'
}

Solution

  • 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