22

I'm trying to build an ear using Gradle.
I've my project tree like:

/project
|
|--> /web-application
|    |
|    |--> /src (stuff of web app)
|    |
|    |--> build.gradle
|
|--> build-gradle
|--> settings.gradle

I'm trying to generate the ear using the ear plugin, but when I do gradle assemble I have the war created under the build directory of the web-application, but inside the generated ear I have a jar of the web application. The gradle configuration files are very simple, here they are:

project/build.gradle

apply plugin: 'ear'

repositories {
    mavenCentral()
}

dependencies {
    deploy project(':web-application')
    earlib group: 'log4j', name: 'log4j', version: '1.2.15', ext: 'jar'
}

project/web-application/build.gradle

apply plugin: 'war'

repositories {
   mavenCentral()
}

dependencies {
    compile group: 'log4j', name: 'log4j', version: '1.2.15', ext: 'jar'
}

What I did wrong?

I notice that also the bundled samples for the war plugin, have the same problem... Thanks in advance

rascio
  • 8,968
  • 19
  • 68
  • 108

2 Answers2

33

SOLVED!

It needs to configure the WAR module inside the EAR project as:

dependencies {
    deploy project(path:':web-application', configuration:'archives')
    earlib group: 'log4j', name: 'log4j', version: '1.2.15', ext: 'jar'
}
rascio
  • 8,968
  • 19
  • 68
  • 108
1

You can avoid specifying a configuration for each deploy dependency using something like this:

allprojects {
  plugins.withType(WarPlugin) {
    // Set default configuration as WAR archive if WAR plugin is used
    configurations {
      'default' {
        extendsFrom = [archives]
      }
    }
  }
}

...

dependencies {
  deploy project(':web-application')
}
Vyacheslav Shvets
  • 1,735
  • 14
  • 23