Gradle Setting Manifest Class-Path on Jars in Ear

(rc) #1

I’ve posted the following question and answer on StackOverflow. Is there a better way to do this? Can the Ear plugin set the Class-Path dependencies automatically? Also, is there a best-practice way to set up these types of builds?

Problem/Question reposted here: I’m using Gradle and have a multi-project build using Java EE. The project directory structure looks like this:

–/build.gradle --/defaults.gradle --/settings.gradle --/common-ejb --/common-ejb/build.gradle --/logging --/logging/build.gradle --/project1 --/project1/build.gradle --/project1-ejb --/project1-ejb/build.gradle --/project2 --/project2/build.gradle --/project2-ejb --/project2-ejb/build.gradle

project1 and project2 are individual ears that get deployed. They both reuse a number of EJBs from common-ejb and share some other library dependencies that aren’t relevant for this question.

After performing the build: project1.ear looks like:

–/lib/log4j.jar --/lib/logging.jar --/META-INF/application.xml --/META-INF/MANIFEST.MF --/common-ejb.jar --/project1-ejb.jar

Gradle properly creates the application.xml to load EJBs from both projects. Unfortunately, project1-ejb.jar will fail to load due to dependencies on common-ejb.jar. The project1-ejb.jar/META-INF/MANIFEST.MF needs to have the Class-Path set with common-ejb.jar since it’s not in the lib/ directory.

I was able to set it scanning the dependencies in the Ear. Gradle knows the dependencies for the Class-Path, so it should be able do this automatically. Is there a way to set this up?