如何使用 Gradle 运行 Jetty

wes*_*eyy 5 java eclipse jetty jersey gradle

我有一个 Gradle 项目,我正在尝试用 Jetty 运行它。我的build.gradle文件如下所示。

构建.gradle

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'jetty'

[jettyRun, jettyRunWar]*.httpPort = 8080
[jettyRun, jettyRunWar]*.contextPath = ''
[jettyRun, jettyRunWar]*.daemon = true
[jettyRun, jettyRunWar, jettyStop]*.stopPort = 8081
[jettyRun, jettyRunWar, jettyStop]*.stopKey = 'stop'

repositories {
    mavenCentral()
}

sourceCompatibility = 1.8
targetCompatibility = 1.8

sourceSets {
    test {
        java {
            srcDirs = ['src/test/java']
        }
    }
}

dependencies {
    compile 'org.glassfish.jersey.containers:jersey-container-servlet:2.14'
    compile 'org.glassfish.jersey.media:jersey-media-json-jackson:2.14'
    compile 'com.google.guava:guava:14.0.1'
    testCompile 'junit:junit:4.12'
    testCompile 'org.hamcrest:hamcrest-all:1.3'
    testCompile 'org.mockito:mockito-all:1.10.19'
    testCompile 'org.eclipse.jetty:jetty-server:9.4.7.v20170914'
    testCompile 'org.eclipse.jetty:jetty-webapp:9.4.7.v20170914'
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试从命令行运行该项目,我使用的命令是:

  1. ./gradlew它应该构建项目,并输出以下内容:

    Jetty 插件已被弃用,并计划在 Gradle 4.0 中删除。考虑使用 Gretty ( https://github.com/akhikhl/gretty ) 插件。在 build_6xw4u3prr68h02k136x2vqowd.run(/myproject/build.gradle:3) :帮助

    欢迎使用 Gradle 3.2.1。

  2. gradle jettyRun失败的原因是找不到 id 为“jetty”的插件。

那么问题来了,我该如何运行这样一个项目呢?请注意,我没有编写这个项目,我只需要在本地计算机上运行它。

LeY*_*ble 3

我不是 Gradle 专家,只是一个初学者,但我想我找到了一些可以帮助你的东西。我还阅读了有关将 jetty 与 gradle 一起使用的内容,因为我经常将它与 Maven 一起使用。

事实证明,Jetty 作为插件不再受支持,您可以在这里找到: https: //docs.gradle.org/current/userguide/jetty_plugin.html

相反,您应该使用 gretty 来达到相同的目的: https://plugins.gradle.org/plugin/org.gretty

希望这有帮助。

  • 我曾经不愉快地使用过的最糟糕的插件..我很欣赏你的回答。 (2认同)