We have multiple war files in different projects, say A and B, sharing common resources like images. The common resources are placed in a war module in a separate project E. And this war file is added as dependency in all the war modules in projects A and B. Currently we are using maven resource plugins to copy these common resources to the root of A and B modules.
Thanks for your quick response. Sure will change it in to jar file.
Currently I am trying this with below configuration, but the files are not copied in to the generated war file. They are only copied to build/libs folder. How to specify the destination correctly?
configurations {
commonWebResources
}
task extractApi(type: Copy) {
print 'File : ' + configurations.commonWebResources.singleFile
from zipTree(configurations.commonWebResources.singleFile)
into file("${project.buildDir}/libs/")
}
compileJava.dependsOn(extractApi)
Thank you. I am looking for the 3rd option. The below one seems to be working. The only issue is that I am not able to exclude some files
war {
from (zipTree(configurations.commonWebResources.singleFile)) {
exclude '*web.xml'
}
into("/")
}
I want to exclude the WEB-INF/web.xml of the common-web.war file while copying contents to my destination web module. But this is being added as duplicate entry.
I am just adding a generic comment here as @Lance_Java has already answered your question. When people are new to Gradle they tend to look for a UnpackZip task.
The thing to remember is that all copying out of archives can be done via the Copy task. zipTree and tarTree are your friends when using archives as sources. Looking inside archives uses a CopySpec just like a normal copy Copy or project.copy would. LEarn how to use the CopySpec syntax and you’ll be amazed how simple Gradle makes it to copy stuff around.