2

I have a project with two sub-projects: a dependency jar and a webapp. I'm using the eclipse-wtp plugin:

allprojects {
    apply plugin: 'java'
    apply plugin: 'eclipse-wtp'
}

The dependency generates some resources (for example, by downloading and unzipping a tarball). The dependency has a block to configure the generated resource dir as an output:

def baseGenDir = "${buildDir}/generated-resources/main"

sourceSets {
    main {
        output.dir(baseGenDir, builtBy: 'unzipDependency')
    }
}

The webapp depends on the dependency:

dependencies {
    compile project(':dependency')
}

If I ./gradlew build, the webapp's war includes a dependency-0.0.1-SNAPSHOT.jar that includes the generated files.

But if I publish the webapp to Tomcat in Eclipse, I get ~/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/webapp/WEB-INF/lib/dependency.jar that does not contain the generated files. It has .class files for my .java source files, but not the resources from build/generated-resources/main. Attempts to load the resources fail - they're not available in the webapp's classpath.

How do I get the generated resources into the jar that Eclipse generates for Tomcat?

Sample project: https://github.com/ms1111/test-gen-resource

Update 2018-02-12

At this time it's not possible to have Buildship run a task to generate resources automatically (#265, #266).

The following block will tell Buildship to publish generated resources:

eclipse {
    wtp {
        component {
            // Make sure generated resources
            // get included in the jars published to Eclipse's Tomcat
            resource sourcePath: "build/generated-resources/main", deployPath: '/'
        }
    }
}

But the resources must already exist at the time Buildship generates .settings/org.eclipse.wst.common.component, so there's a dance required:

  1. Import project
  2. Run full gradle build
  3. Refresh Gradle for any modules with generated sources
  4. Clean the Tomcat server
MZS
  • 573
  • 4
  • 12

0 Answers0