在Gradle中创建具有不同依赖关系的多个.WAR文件 [英] Create multiple .WAR files with different dependencies in Gradle

查看:127
本文介绍了在Gradle中创建具有不同依赖关系的多个.WAR文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用war插件为gradle中的项目生成一个简单的.WAR文件。我想知道如何配置gradle,以便我可以创建4个具有不同依赖关系的不同的.WAR文件。



我已经使用jar配置了依赖项编译配置进入分配所需的。 src中的任何代码都不依赖于这两个jar包,但我想知道如何配置该项目来创建




  • a标准.WAR文件,其中包含依赖图中的所有jar(即使它们没有被使用 - 那没关系 - 我正在测试一些内容)

  • 另一个标准-qas-only。仅包含qas.jar的WAR文件

  • 另一个包含qas.jar和log4j的standard-qas-log4j.WAR文件



我配置了什么任务来使生成的工件使用特定的依赖配置?



仅供编译所需的jar在这种情况下是qas.jar。



下面的示例创建了一个war文件,其中只包含一个jar,但我希望生成5个不同的.war文件jb。

> build.gradle

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

dependencies {
编译文件('/ lib / qas.jar','/ lib / axis1-1.4.jar','/ lib / axis2-kernel-1.3.jar','/ lib / dom4j-1.6.1。 ('/ lib / j2ee-1.4.03.jar')
}

war {
classpath = ['/lib/qas.jar']
}

任务dist(dependsOn:'war')<< {
copy {
from war.archivePath
intodist /
}
}


解决方案

我对你实际尝试构建的WAR分发有点困惑。您可以轻松修改它以创建其他WAR文件。这里有一种方法可以实现这一点:

 任务createStandardWar(类型:War,dependsOn:classes){
baseName = 'standard'
destinationDir = file($ buildDir / dist)
}

任务createStandardWarQasOnly(类型:War,dependsOn:classes){
baseName =' standard-qas-only'
destinationDir = file($ buildDir / dist)
classpath = war.classpath.minus(files('/ lib / axis1-1.4.jar','/ lib / axis2-kernel-1.3.jar','/ lib / dom4j-1.6.1.jar','/ lib / log4j-1.2.14.jar'))
}

任务createStandardWarQasAndLog4J(type:War,dependsOn:classes){
aseName ='standard-qas-log4j'
destinationDir = file($ buildDir / dist)
classpath = war.classpath.minus (文件('/ lib / axis1-1.4.jar','/ lib / axis2-kernel-1.3.jar','/ lib / dom4j-1.6.1.jar'))
}

任务createDists(dependsOn:[createStandardWar,createStandardWarQasOnly,createStandardWarQasAndLog4J])

此构建脚本摘录通过声明类型为战争。它假定你仍然希望在WAR文件中将编译后的源文件放置在 WEB-INF / classes 下,所以我没有将它从类路径中移除。分发结束于 build / dist 目录中。任务 createDists 创建它们全部。


I am using the war plugin to generate a simple .WAR file for my project in gradle. I'd like to know how to configure gradle so that I can create 4 different .WAR files with different dependencies.

I've configured the dependency compile configuration with the jars that are needed to go into the distribution. None of the code in the src depends on a couple of these jars but I would like to know how to configure the project to create

  • a standard.WAR file that contains all of the jars in the dependency graph (Even though they aren't used - that is OK - I am testing something)
  • another standard-qas-only.WAR file that only contains the qas.jar
  • another standard-qas-log4j.WAR file that contains qas.jar and log4j

What tasks do i configure to have the artifact generated use a particular dependency configuration?

FYI: The only jar that is required for compilation is qas.jar in this case.

My example below creates a war file that only includes one jar but i'd like to have 5 different .war files generated with different jars.

build.gradle

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

dependencies {
    compile files('/lib/qas.jar','/lib/axis1-1.4.jar','/lib/axis2-kernel-1.3.jar','/lib/dom4j-1.6.1.jar','/lib/log4j-1.2.14.jar')
    providedCompile files('/lib/j2ee-1.4.03.jar')
}

war {
    classpath = ['/lib/qas.jar']
}

task dist(dependsOn: 'war') << {
    copy {
        from war.archivePath
        into "dist/"
    }
}

解决方案

I got a bit confused on how many WAR distributions you are actually trying to build. You can easily modify it to create additional WAR files. Here's one approach to make this happen:

task createStandardWar(type: War, dependsOn: classes) {
    baseName = 'standard'
    destinationDir = file("$buildDir/dist")
}

task createStandardWarQasOnly(type: War, dependsOn: classes) {
    baseName = 'standard-qas-only'
    destinationDir = file("$buildDir/dist")
    classpath = war.classpath.minus(files('/lib/axis1-1.4.jar','/lib/axis2-kernel-1.3.jar','/lib/dom4j-1.6.1.jar','/lib/log4j-1.2.14.jar'))
}

task createStandardWarQasAndLog4J(type: War, dependsOn: classes) {
    baseName = 'standard-qas-log4j'
    destinationDir = file("$buildDir/dist")
    classpath = war.classpath.minus(files('/lib/axis1-1.4.jar','/lib/axis2-kernel-1.3.jar','/lib/dom4j-1.6.1.jar'))
}

task createDists(dependsOn: [createStandardWar, createStandardWarQasOnly, createStandardWarQasAndLog4J])

This build script excerpt creates three different WAR files by declaring enhanced tasks of type War. It assumes that you still want to have your compiled source files under WEB-INF/classes within the WAR files so I didn't remove it from the classpath. The distributions end up in the directory build/dist. The task createDists creates all of them.

这篇关于在Gradle中创建具有不同依赖关系的多个.WAR文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆