Do you have trouble creating the ear layout you like to see? Maybe this little tip will help.
Let’s assume we have an ejb.jar
which should go into the ear root
. Its dependencies should be placed in the lib
folder of the ear.
app.ear
|-- ejb.jar
\-- lib
|-- dep.jar
|-- ...
The ear plugin does have two configurations which are used to control what is put where into the ear.
- first is the
deploy
configuration. All dependencies will be placed into the earroot
.deploy
is not transitive, ie. if we usedeploy project(':ejb')
,ejb.jar
will be placed into theroot
of the ear and it will ignore all dependencies ofproject(':ejb')
:app.ear \-- ejb.jar
- second is the
earlib
configuration. All dependencies will be placed into thelib
folder of the ear.earlib
is transitive, ie. if we useearlib project(':ejb')
,ejb.jar
and all dependencies ofproject(':ejb')
will be placed intolib
:app.ear |-- lib |-- ejb.jar \-- dep.jar
Looks like both do not what we need.
The trick is to use both.
deploy
to put project(':ejb')
into the root and earlib
to put its dependencies into lib
:
dependencies {
deploy project(':ejb')
earlib project(':ejb')
}
The result will look like this:
app.ear
|-- ejb.jar
\-- lib
|-- ejb.jar // ups...!
|-- dep.jar
|-- ...
Better but still not what we want. We now have an ejb.jar
in root
and one in lib
. How do we get rid of the duplicate ejb.jar
?
The trick is to explicitly select the compile
configuration of project(':ejb')
The compile
configuration does only contain the dependencies and not the ejb.jar
artifact. Exactly what should go into the lib
folder (we can’t use the runtime
configuration because it does include the ejb.jar
, we will need it at runtime.. :-)):
dependencies {
deploy project(':ejb')
earlib project(path: ':ejb', configuration: 'compile')
}
Which does create the ear we want:
app.ear
|-- ejb.jar
\-- lib
|-- dep.jar
|-- ...
Finally!
We are missing now some of the runtime dependencies of ejb.jar in the lib folder. Obviously these runtime-only dependencies do not appear in the compile configuration. How to cope with that?
Sorry, I haven’t used that for a while. So i have no idea.
cheers