providedCompile is adding jars into the war


(randeep2000au) #1

So our basic project layout is like this, with each project having their own build.gradle file.

root --client (front end stuff like html/css/js) --service (java classes/creates a war)

The root project assembles a war by copying the html/js/css stuff from client, and the compiled java classes from service. We are using tomcat because the current jetty plugin isn’t quite cutting it. In the service project’s build.gradle, we call:

dependencies {
...
providedCompile "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
            "org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}",
            "org.apache.tomcat.embed:tomcat-embed-logging-log4j:${tomcatVersion}"
...
}

In the service.war file that gets assembled, these tomcat jars do not appear in service.war/WEB-INF/lib, as expected, because we use provided compile.

In the root project, we get the libraries that service uses to include in the war by:

dependencies {
    compile project(':service')
}

However, this results in the tomcat jars appearing in the root.war when we assemble them, which we don’t want. A workaround for now is:

dependencies {
    ext{
        tomcatVersion = '7.0.37'
    }
    compile project(':service')
    providedCompile "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}",
            "org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}",
            "org.apache.tomcat.embed:tomcat-embed-logging-log4j:${tomcatVersion}"
}

Is this a bug or expected behaviour? I am inclined to think it is a bug, because we also have testCompile dependencies in the service project, and their jars do not appear in either the service.war or root.war