Guava classes are copied to my "classes" folder

(Alex Sko) #1

I see google guava’s classes in my productmodel/build/classes/main folder when I execute “gradle compileJava”:

  • com/google/common/annotations

  • com/google/common/base

  • com/google/common/collect

while I’d only expect to see my own classes in this folder.

These Guava files end up in -warfile-/WEB-INF/lib/productmodel.jar. While I also have -warfile-/WEB-INF/lib/guava-12.0.jar and I’d expect the Google Guava classes to be loaded from there.

so why are these Google Guava classes copied to my “classes” folder? why only them and not all the other libraries I’m using?

my productmodel/build.gradle:

  apply plugin: 'war'
  def gwtVersion = '2.4.0'
def gwtModules = ['ProductModel']
def gwtStartupUrls = ['/']
  dependencies {
    compile project(':common')
    compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
  compile group: '', name: 'guava-gwt', version: '12.0'
    // DO NOT use the latest 2011.1.297684 version: it leads to GWT application deadlock on startup!
    compile group: 'com.perforce', name: 'p4java', version: '2010.1.269249'
      def slf4j_version = "1.6.6"
      // Compile GWT libs, needed for gwtCompile and the javaCompile
    // Also includes the servlet-api
    providedCompile "$gwtVersion"
    providedCompile "$gwtVersion"
      // Needed for GWT compile and at runtime for RequestBuilder
    // Specify two artifacts as workaround for GRADLE-1934
    compile('javax.validation:validation-api:1.0.0.GA') {
        artifact {
            name = 'validation-api'
            type = 'jar'
        artifact {
            name = 'validation-api'
            type = 'jar'
            classifier = 'sources'
      // Runtime GWT libraries, should be included in WAR
    runtime ''
    runtime 'org.json:json:20090211'
            // Use jdk1.4 logging with SLF4J
            //Jbcrypt is used to encrypt users' passwords.
  // read environment variables, including variables passed by jenkins continuous integration server
def env = System.getenv()
def buildNumber = env.BUILD_NUMBER
     // set by Jenkins server
  if (buildNumber) {
    println "Found build number (usually set by Jenkins): $buildNumber. Will add it to the version info."
} else {
    buildNumber = ""
  processResources {
    // Uncomment this to force "processResources" step even if there are no modified files.
    // This is useful if you want to force Gradle to update file.
    // outputs.upToDateWhen { false }
    filter ReplaceTokens, tokens: [
            timestamp: new Date().dateTimeString,
            build_number: buildNumber
  def buildDir = "${project.buildDir}/gwt"
def extraDir = "${project.buildDir}/extra"
  task compileGwt(dependsOn: classes, type: JavaExec) {
    inputs.dir sourceSets.main.output.resourcesDir
    outputs.dir buildDir
      // Workaround for incremental build (GRADLE-1483)
    outputs.upToDateSpec = new org.gradle.api.specs.AndSpec()
      doFirst {
      main = ''
      classpath {
         // Java source
  // Generated resources
    // Generated classes
     // Deps
      args =
                '', // Your GWT module
                '-war', buildDir,
                '-logLevel', 'INFO',
                '-localWorkers', '2',
                '-style', 'DETAILED',
                '-extra', extraDir,
                // '-draftCompile' // Speeds up compile with 25%
      maxHeapSize = '1000M'
  // pack the classes into the Jar file
jar.enabled = true
  war.dependsOn compileGwt
war {
    from buildDir
    classpath = jar.outputs.files + configurations.runtime - configurations.providedRuntime

my common/build.gradle:

dependencies {
    compile group: '', name: 'guava-gwt', version: '12.0'

my root level build.gradle:

subprojects {
      apply plugin: 'java'
      sourceCompatibility = 1.7
      repositories {
      dependencies {
        testCompile 'junit:junit:4.11'

root level settings.gradle:

include "common", "launcher", "productmodel"

(Luke Daley) #2

Not sure why this would be happening.

Can you please try reproducing with a small, simple, build that I can also run?

(Alex Sko) #3

I reproduced it with some minimal configuration with just 1 java class in 1 module. how can I send you the ZIP file?

(Alex Sko) #4

here’s my only java class:


package my.shared.service;
  public class AppVersionBuilder {
  public static String getFullVersionString() {
    String fullString = "stub here";
    if (!Strings.isNullOrEmpty(fullString)
            && !"@build_number@".equals(fullString)) {
      fullString += "-" + fullString;
    return fullString;


include "mymodule"


apply plugin: 'war'
  dependencies {
    compile group: '', name: 'guava-gwt', version: '12.0'

(Peter Niederwieser) #5

Do some of the (Guava) Jars on your compile class path (additionally) contain Java sources? Note that javac will, by default, compile source files found on its compile class path just like “regular” source files.

(Alex Sko) #6

yes, I see guava-gwt-12.0.jar has some java source files in it. same with guava-gwt-14.0.1.jar (both loaded from Maven Central).

what can we do to avoid having those Guava classes in our jar file?

(Peter Niederwieser) #7

Try ‘compileJava.options.compilerArgs = ["-implicit:none"]’.

(Alex Sko) #8

this helped, thank you!