Search code examples
javaspringherokugradlegretty

Gretty: Duplicate fragment name: org_apache_jasper


I use gretty to easily run a dev server and webapp-runner for deployment to heroku.

The following is my 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)

If I remove webapp-runner everything runs fine, but with it I get the following error when trying to start gretty:

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

Not an expert but I figure its something to do with the fact that both gretty and webapp-runner download similar files and that's causing a clash?

Would really appreciate some info on this. How do I get past this? Is there a better way to have a dev server + be able to deploy to heroku? (maybe use webapp-runner for both?)


Solution

  • I recommend running locally the same way as Heroku runs your app, with these commands:

    $ ./gradlew stage
    $ heroku local web
    

    If you want to use gretty for development, you'll need to exclude webapp-runner from your dev build (maybe with a stageDev task), and exclude gretty from your stage build.