War project missing resources in library project .jar file


(David Sykes) #1

We are in the process of migrating an existing multi-project setup from Ant to Gradle. One of the artifacts we produce is a .war file containing a GWT-based web client and Java servlet based server, all packaged into the same .war.

This is all on Gradle 3.5 running on JDK 1.8.

The build configuration looks like this:

work/data-layer/build.gradle

apply plugin: 'java'

sourceSets {
  main {
    java {
      srcDirs = ['source', 'source-gen']
    }
    resources {
      srcDirs = ['source', 'source-gen']
    }
  }
}

task codeGen(type: JavaExec) {
  // run a code generator to generate mapping .xml files in the ./source-gen folder
}

compileJava.dependsOn codeGen

work\middleware\build.gradle

apply plugin: 'java'

sourceSets {
  // same as in data-layer
}

dependencies {
  compile project('"work:data-layer')
}

work/api/build.gradle

apply plugin: 'java'

sourceSets {
  // as in data-layer and middleware
}

dependencies {
  compile project(':work:middleware')
}

work/webapp/build.gradle

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'gwt-gradle-plugin'

dependencies {
  // some GWT dependencies

  runtime project('api')
}

The build runs without error and produces a .war file that appears to contain all of the necessary .jar files. However, when examining the contents of the data-layer.jar file I see that it is missing all of the resources.

If I examine the data-layer.jar file in the work/data-layer/build/libs directory, it is complete and correctly contains all of the resources.

How can I go about figuring out why the .jar included in the .war file is missing the resources?

Thanks


(David Sykes) #2

So, in hindsight it is completely obvious what I was doing wrong.

Since I was generating resource files as well as source files, I needed to make the processResources task also depend on my codeGen task!