The mywar project uses the war plugin and seems to work fine, creating a war archive.
However, when I try to assemble the ear, Gradle creates a jar archive of the war project and includes the jar as an ejb dependency! Even the application.xml says that it’s an ejb. Why isn’t the war project included as a war?
....
dependencies {
//following dependencies will become the ear modules and placed in the ear root
deploy project(':war')
//following dependencies will become ear libs and placed in a dir configured via libDirName property
earlib group: 'log4j', name: 'log4j', version: '1.2.15', ext: 'jar'
}
...
So do I need to add a custom configuration to get this option to work? When I try modifying my dependency with the “configuration: ‘archives’” option I get an error:
Could not find method project() for arguments [{configuration=archives}, :rest-facade] on root project ‘aggregator-v2’.
Perfect. Thanks. It took me a minute to realize that I’d need to explicitly identify the first argument as path:, but then it worked perfectly! Thanks!
Thanks for the workaround. This doesn’t work properly if you use jar.enabled = true on the war project, however. In that case you get both the WAR and EAR in the EAR. The JAR is listed as an EJB module in the application.xml. For now I have removed jar.enabled = true from my script because I didn’t really need it but that might not be an option for everyone.
Where: Build file … * What went wrong: A problem occurred evaluating root project ‘myEarProject’. > Could not find method project() for arguments [{configuration=archives}, :myWar] on root project ‘myEarProject’.
Stacktrace: > Exception is: org.gradle.api.GradleScriptException: A problem occurred evaluating root project ‘myEarProject’.
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory .java:54)
… Caused by: org.gradle.api.internal.MissingMethodException: Could not find method project() for arguments [{configuration =archives}, :myWar] on root project ‘myEarProject’.
at org.gradle.api.internal.AbstractDynamicObject.methodMissingException(AbstractDynamicObject.java:60)
…
is there example how to declare: configuration: ‘archives’ ?
I only know, as I was a minor part the of war/ear rework in gradle that happened when the default and archives configurations were split apart a bit.
Right now, a project() dependency always attempts to pull from the ‘default’ configuration. But for cases like this, there really should be an earLibs or similar configuration that is used by the ear plugin. The war plugin would automatically add the war output to that configuration, and there should be an ‘ejb-jar’ plugin that simply takes the jar output and adds that to that configuration as well. (Or something to that effect). If an ‘earLib’ configuration was not available from a depended upon project, then it could possibly fall back to using the ‘default’ configuration.
This workaround sounds to be working for me too. However, since I don’t just generate the war archive but also sources.jar and javadoc.jar for the web project, the ear is including all three archives (war and the two jars). Is there a way to add a third parameter to include only the war file in ear and not the other two jars?
@Shin. I’m not sure if I followed you properly but that didn’t seem to work for me. However, I added a configurations something like below to get my ear package exclude the sources and javadoc jar files of the war project.
//package in EAR
apply plugin: 'java'
apply plugin: 'ear'
//EAR dependencies
ear{
dependencies {
deploy project(path: ':myWeb', configuration: 'archives')
}
//exclude the src and doc jar files from the ear package
configurations.archives{
exclude '*-src.jar'
exclude '*-doc.jar'
}
}
I have a similar issue while generating ear file. The basic doubt that I have is when you say myWeb as your war file, where is the defined. I mean where exactly are building your war file. Is it included in the same file or in a different file. Could you please explain me.
I am able to successfully generate the war file and got stuck at generating the ear file with war file + META-INF folder as per my requirement.