java - gradle build<配置名称> : different packaging for ear and war (gradle v2. 3)

标签 java gradle war ear

我想使用 gradle v2.3 配置以两种方式打包我的应用程序:

  1. ear 包含 ear 的 lib 目录 中的所有库以及 Ear 内的多重 war (使用 providedCompileearlib 声明的 deps >)
  2. 多个 war 文件,每个 war 中都包含库,位于 WEB-INF/lib 中(使用 compile 声明的 deps)

如果我每次需要不同的打包时都修改 build.gradle 文件,我就可以执行这两个任务。 我想使用配置来选择jar是否包含在war文件中,方法是使用gradle build<ConfigurationName> .

基于帮助和 StackOverflow post How to use uploadConfigurationName and buildConfigurationName我编写了以下文件(这是针对其中一场 war 的):

apply plugin: 'war'

configurations {
        packEar
        packWar
    }

dependencies {
    configurations.packEar {
        providedCompile project(':Common') // jars will be included using earlib
    }

    configurations.packWar {
        compile project(':Common') // jars included in war
    }
}

artifacts {
        packWar war
        packEar war
}

问题是命令 gradle buildpackWargradle buildpackEar产生平等 war ,不包括来自Commonjar项目。 如果我将 packEar 的配置从 providedCompile 更改为至compile两者都会产生包含 jar 的 war 。

其他信息:我尝试使用 extendFrom compile / providedCompile但这似乎没有影响任何事情。我包括buildpackWarbuildpackEar方法,但它也不起作用(可能是我以错误的方式使用了这些方法)。

感谢您的回答!

最诚挚的问候, 兹加

最佳答案

compileprovidedCompile 是它们自己的配置,因此您要将 Common 项目添加到其中,而不是 packWarpackEar 配置。像这样的东西应该有效:

项目mywar

apply plugin: 'war'
apply plugin: 'java'

repositories {
    jcenter()
}

configurations {
    shareable
}

dependencies {
    shareable project(':common')
}

task standaloneWar(type: War, dependsOn: war) {
    baseName = war.baseName + '-standalone'
    classpath = war.classpath + configurations.shareable
}

artifacts {
    archives standaloneWar
}

项目myear

apply plugin: 'ear'
apply plugin: 'java'

evaluationDependsOn ':mywar'

repositories {
    jcenter()
}

dependencies {
    deploy project(':mywar')
    earlib project(path: ':mywar', configuration: 'shareable')
}

它将产生三个主要工件:

  • mywar.war,不包含 shareable 中的任何依赖项(如 common)
  • mywar-standalone.war,其中包含 shareable 中的依赖项
  • myear.ear,其中包含根目录中的 mywar.war(技术上是 mywar.jar)以及来自 的依赖项/lib 下的 mywar 项目中的 shareable(例如 common)

关于java - gradle build<配置名称> : different packaging for ear and war (gradle v2. 3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29663938/

相关文章:

Java对象切片困惑

java - 将另一个类添加到现有类中

android - generatedDensities 弃用

android - 无法同步 Gradle,找不到 com.android.support :support-annotations:23. 3.0

java - 构建单个 Spring Boot WAR 项目以进行部署

java - 不使用 main 方法打印 hello world

java - 我如何将此 Activity 转换为 fragment 并将 fragment 转换为导航

gradle - 在gradle中使用fmpp生成java文件

java - 没有名为 EntityManager 的持久性提供程序

java - war 级别初始化, "main"为 war