Ear Project with war subprojects


(Mark Lamb) #1

Hi there,

So I’m trying to create a root level ear project that will include multiple war projects and I can’t seem to get it to work. To pare it down to the simplest level, lets suppose I have a directory structure like this:

myEar/
├── build.gradle
├── myWar1
│   ├── build.gradle
│   └── src
│       └── main
│           ├── java
│           │   └── com
│           │       └── foo
│           │           └── hello.java
│           ├── resources
│           └── webapp
│               ├── test.html
│               └── WEB-INF
│                   └── web.xml
├── myWar2
│   ├── build.gradle
│   └── src
│       └── main
│           ├── java
│           │   └── com
│           │       └── foo
│           │           └── hello.java
│           ├── resources
│           └── webapp
│               ├── test.html
│               └── WEB-INF
│                   └── web.xml
├── settings.gradle
└── src
    └── main
        └── application
            └── application.xml

Each build.gradle file in the myWarX subporjects is simply this:

defaultTasks 'war'
apply plugin: 'war'

When I run gradle from inside the myWar1/2 folder I get the expected output:

 jar -xvf myWar1.war 
  created: META-INF/
 inflated: META-INF/MANIFEST.MF
  created: WEB-INF/
  created: WEB-INF/classes/
  created: WEB-INF/classes/com/
  created: WEB-INF/classes/com/foo/
 inflated: WEB-INF/classes/com/foo/hello.class
 inflated: WEB-INF/web.xml
 inflated: test.html

Now at the root project level myEar, I have the following settings.gradle file:

include “:myWar1”, “:myWar2”

and build.gradle looks like this:

defaultTasks 'assemble'

allprojects {

    apply plugin: 'java'
    apply plugin: 'eclipse'
    apply plugin: 'war'
    apply plugin: 'ear'
}

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

Now when I run this, it builds an myEar.ear file sure enough but both the war projects are being listed as myWar1/2.ear in the archive. In addition, if I expand out those ear files, it is missing things like the html files and the web.xml:

jar -xvf myEar.ear 
  created: META-INF/
 inflated: META-INF/MANIFEST.MF
 inflated: myWar1.ear
 inflated: myWar2.ear
 inflated: application.xml
 inflated: META-INF/application.xml

jar -xvf myWar1.ear 
  created: META-INF/
 inflated: META-INF/MANIFEST.MF
  created: com/
  created: com/foo/
 inflated: com/foo/hello.class
 inflated: META-INF/application.xml

It seems like there should be a simple solution to this but I can’t for the life of me find it. Any help would be gratly appreciated.

Thanks,
Marcus.


(Mark Lamb) #2

ok I’m an idiot. It was because I am applying the ‘ear’ plugin to allprojects. If I replace:

allprojects {
    apply plugin: 'java'
    apply plugin: 'eclipse'
    apply plugin: 'war'
    apply plugin: 'ear'
}

with simply

apply plugin 'ear'

everything works as intended.