Gradle - 在EAR中包含多个WAR项目

时间:2016-11-23 11:32:07

标签: gradle war ear

所以我正在尝试创建一个包含多个war项目的根级耳朵项目,我似乎无法让它工作。为了减少到最简单的级别,我们假设我有一个这样的目录结构:

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

myWarX子目录中的每个build.gradle文件都是这样的:

defaultTasks 'war'
apply plugin: 'war'

当我从myWar1 / 2文件夹中运行gradle时,我得到了预期的输出:

 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

现在在根项目级myEar,我有以下settings.gradle文件:

包括“:myWar1”,“:myWar2”

和build.gradle看起来像这样:

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

现在,当我运行它时,它确实构建了一个myEar.ear文件,但两个war项目都在归档中列为myWar1 / 2.ear。另外,如果我扩展那些ear文件,它会丢失诸如html文件和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

似乎应该有一个简单的解决方案,但我不能为我的生活找到它。任何帮助都会得到很好的赞赏。

谢谢, 马库斯。

1 个答案:

答案 0 :(得分:1)

好吧,我是个白痴。这是因为我正在应用耳朵'插件到所有项目。如果我更换:

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

只需

apply plugin 'ear'

一切都按预期运作。