[英]How to include all files from jar into war using Gradle
I was trying plugins: 我正在尝试插件:
Currently I'm trying write script: 目前,我正在尝试编写脚本:
dependencies {
/* jar, his files I would like to include in war */
compile project(':my_jar_1')
}
war {
/* Step 1. Copy all from my_jar_1 into WEB-INF/classes */
into('WEB-INF/classes') {
from configurations.compile
.filter { it.name.startsWith("my_jar_1") }
.collect { zipTree(it).matching { exclude 'META-INF/**/*.*' }}
}
/* Step 2. Deleting jar from war WEB-INF/lib. I got stuck here. It println, but doesn't delete jar */
doLast {
zipTree('build/libs/war_1-0.0.0.war').files.each {
if (it.path.endsWith('.jar')) {
delete it
println 'DELETED ' + it.path
}
}
}
}
Could somebody tell me how to make it work? 有人可以告诉我如何使其工作吗? Or maybe smb know more elegant solution?
或者也许smb知道更优雅的解决方案?
Also I was trying to declare my own configuration 我也在尝试声明自己的配置
configurations { overlay }
dependencies {
overlay project(':my_jar_1')
}
war {
into('WEB-INF/classes') {
from configurations.overlay
...
But it shows error 但它显示错误
FAILURE: Build failed with an exception.
失败:构建失败,发生异常。
- What went wrong: Failed to capture snapshot of input files for task 'war' property 'rootSpec$1$1' during up-to-date check.
出了什么问题:在最新检查期间无法捕获任务'war'属性'rootSpec $ 1 $ 1'的输入文件的快照。
Failed to create MD5 hash for file '/home/user/projects/OveralJarToWar/my_jar_1/build/libs/my_jar_1-1.0-SNAPSHOT.jar'.
无法为文件“ /home/user/projects/OveralJarToWar/my_jar_1/build/libs/my_jar_1-1.0-SNAPSHOT.jar”创建MD5哈希。
The content of WEB-INF/lib
and WEB-INF/classes
is configured by single property classpath
of war
task. WEB-INF/lib
和WEB-INF/classes
内容由war
任务的单个属性classpath
配置。 According to documentation: 根据文档:
Any JAR or ZIP files in this classpath are included in the WEB-INF/lib directory.
该类路径中的所有JAR或ZIP文件都包含在WEB-INF / lib目录中。 Any directories in this classpath are included in the WEB-INF/classes directory
该类路径中的所有目录都包含在WEB-INF / classes目录中
So, in your case, the classpath should be modified as follow 因此,在您的情况下,应将classpath修改如下
war {
def myJar = project(':my_jar_1').jar.outputs
def myClassesAndResources = project(':my_jar_1').sourceSets.main.output
classpath = classpath - myJar + myClassesAndResources
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.