Problem with the ear plugin

I’m trying to create an ear using with ear plugin. The ear project has a dependency on a war project, among other dependencies.

Here’s a simplified version of the ear project’s build.gradle.

apply plugin: 'ear'
  dependencies {
     deploy project(':mywar')
 ...
}

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?

According to this http://www.gradle.org/ear_plugin. it should work:

....
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'
}
...

I have the same problem using M5 and M6-snapshots to build samples provided with gradle:

gradle-1.0-milestone-5\samples\ear\earCustomized\ear$ gradle ear
:war:compileJava
:war:processResources UP-TO-DATE
:war:classes
:war:jar
:ear:ear
  BUILD SUCCESSFUL
  Total time: 6.485 secs

There is :war:jar instead of :war:war - as a result, I get war.jar.

It is working in M4…

This now has a jira issue GRADLE-1912.

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.

Using the workaround I still get the ‘.jar’ file instead of the ‘.war’ file into the ear-archive.

configure(ears) {

apply plugin: ‘ear’

}

configure(project(’:suite:sms’)) {

dependencies {

earlib fileTree("$rootProject.projectDir/dependent-jars").include(’*.jar’)

earlib project(’:common-struts’)

earlib project(’:common-webapp’)

deploy project(’:common:ejb-api’)

deploy project(’:common:ejb-impl’)

deploy project(’:common:jmx’)

deploy project(’:common:jmx-persistence’)

deploy project(’:common:persistence’)

deploy project(’:smsgateway:ejb-api’)

deploy project(’:smsgateway:ejb-impl’)

deploy project(’:smsgateway:jmx’)

deploy project(’:smsgateway:persistence’)

deploy project(path: ‘:smsgateway:war’, configuration: ‘archives’)

deploy project(path: ‘:jbossonline:war’, configuration: ‘archives’)

}

}

Workaround worked great for me. I spent part of the day manually fixing this problem and then went home and started googling this problem.

Thanks for the workaround and hopefully this will get fixed quickly since I found it in the 1.0 release.

hello i am new and have the same problem, but this doesn’t work.

dependencies {
    deploy project(path: ':myWar', configuration: 'archives')
}

the error is:

  • 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’ ?

EDIT: corrected the code example

What is the name of the war project? Is it war?

If it is myWar, then it should be

dependencies {

deploy project(path: ‘:myWar’, configuration: ‘archives’) }

The name of the war project ist myWar. I did a mistake in the code example and update my post now.

myWar is not the original project name. but i cant use the original here and so it was a mistake by writing the post. sry

I can reproduce your exact error, but only if the path: key is missing.

dependencies {
  deploy project(':myWar', configuration: 'archives')
}

Please double check that the actual build.gradle file is not missing the “path:” argument as part of the map being implicitly constructed.

-Spencer

Thanks for the workaround. Just hit upon this issue myself.

Out of curiosity, how did you know to use the ‘archives’ configuration? I can’t see it documented.

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.

-Spencer

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?

Thanks! Lal

Published artifacts is probably what you want. So something like:

configurations {
  publishedWar
}
  artifacts {
  publishedWar war
}

So now your dependencies become:

dependencies {
  deploy project(':myWar', configuration: 'publishedWar')
}

If that’s not entirely correct then there’s a whole chapter about publishing artifacts in the docs.

Shin

@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'
 }
}

Thanks

Hi Lal & All,

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.

Appreciate your help here.

Thanks Pavan

A current work-around is

dependencies {
    deploy project(path: ':war', configuration: 'archives')
}