0

我使用 gretty 轻松运行开发服务器和 webapp-runner 以部署到 heroku。

以下是我的gradle.build

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'org.akhikhl.gretty:gretty:+'
    }
}

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse-wtp'
apply plugin: 'idea'
apply plugin: 'org.akhikhl.gretty'

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies {
    compile 'org.springframework:spring-webmvc:4.3.10.RELEASE'
    compile 'org.springframework:spring-orm:4.3.10.RELEASE'
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.0'
    compile group: 'org.hibernate', name: 'hibernate-core', version: '5.2.10.Final'
    compile group: 'org.apache.commons', name: 'commons-dbcp2', version: '2.1.1'
    compile group: 'mysql', name: 'mysql-connector-java', version: '6.0.6'
    compile group: 'org.hibernate.validator', name: 'hibernate-validator', version: '6.0.1.Final'
    compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.0'
    compile group: 'org.postgresql', name: 'postgresql', version: '42.1.4'

    compile 'com.github.jsimone:webapp-runner:8.5.11.3'

}

gretty {
    httpPort = 8080
    servletContainer = 'jetty9'
    contextPath = '/'
}

eclipse {
    wtp {
        component {
            contextPath = '/'
        }
    }
}

///////// Tasks for deployment to heroku

task stage() {
    dependsOn clean, war
}
war.mustRunAfter clean

task copyToLib(type: Copy) {
    dependsOn war
    into "$buildDir/server"
    from(configurations.compile) {
        include "webapp-runner*"
    }
}

stage.dependsOn(copyToLib)

如果我删除 webapp-runner 一切运行正常,但尝试启动 gretty 时出现以下错误:

java.lang.IllegalStateException: Duplicate fragment name: org_apache_jasper for jar

不是专家,但我认为这与 gretty 和 webapp-runner 下载类似文件并导致冲突的事实有关?

真的很感激这方面的一些信息。我该如何度过这个难关?有没有更好的方法让开发服务器+能够部署到heroku?(也许两者都使用 webapp-runner ?)

4

1 回答 1

1

我建议使用与 Heroku 运行应用程序相同的方式在本地运行,使用以下命令:

$ ./gradlew stage
$ heroku local web

如果你想使用 gretty 进行开发,你需要从你的开发构建中排除 webapp-runner(可能有一个任务),并从你的构建中stageDev排除 gretty 。stage

于 2017-08-15T13:11:25.667 回答