我如何 运行 appRunWar 在 build.gradle 中定义的端口以外的端口

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

我在尝试按照 Gretty 文档中的说明更改 Gretty 的端口时遇到问题。

Gradle appRunWar -PhttpPort=8888 

唯一可行的方法是更改​​ build.gradle gretty 块

gretty {
    http = 8888
    contextPath = '/'
}

我在搜索 Gretty Possible Running Build in Different Ports Github 存储库后找到了解决方案。

您需要做的就是按如下方式更改 build.gradle 文件

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

另一种方法是添加以下内容

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

两种解决方案都可以通过将 属性 个参数传递给公会文件

 gradle -PhttpPort=8888