War plugin: How to change tld location folder in war?


(Stéphane Bury) #1

Hi,

I’ve a project which use Struts with some taglibs and I would like to put the TLD files in [WEB-INF\tld], but when I use the command : > gradle war -i

It put all the TLD files in [WEB-INF\lib] with all the JAR files. How can I say to gradle to put it in [WEB-INF\tld] in place of [WEB-INF\lib] ?

Here my gradle script:

//-------------------------------------------
apply plugin: 'war'
...
...
List runTime = [
        ...
        ...
 "org.joda.time:joda-time:1.4@jar",
 "oro:oro:2.0.8@jar",
 "springframework:spring:1.2.5@jar",
 "struts-layout:struts-layout:1.2@jar",
 "struts-menu:struts-menu:2.4.2@jar",
 "struts:struts:1.2.7@jar",
 "taglibs:standard:1.1.1@jar",
 "xerces:xerces:2.4.0@jar",
 "struts:struts-tiles:1.2.7@tld",
  "struts:struts-bean:1.2.7@tld",
  "struts:struts-bean-el:1.2.7@tld",
  "struts:struts-logic:1.2.7@tld",
  "struts:struts-logic-el:1.2.7@tld",
  "struts:struts-html:1.2.7@tld",
  "struts:struts-html-el:1.2.7@tld",
  "struts:struts-nested:1.2.7@tld",
  "birt:birt:1@tld"
]
  dependencies {
 compile runTime
}
   //-------------------------------------------

Thank’s a lot, Fonzy.


(René Groeschke) #2

hey fonzy, one option to achieve this is to configure your war task like this:

war{
 classpath = classpath.filter {File file -> file.name.endsWith("jar")}
    from(configurations.compile){
  exclude "*.jar"
  include "*.tld"
  into("WEB-INF/tld")
 }
}

A more declarative way might be to split up your tld definitions into a dedicated configuration and resolve this configuration in the tld subfolder of your war:

List runTime = [
    "org.joda.time:joda-time:1.4@jar",
    "oro:oro:2.0.8@jar",
    "springframework:spring:1.2.5@jar",
    "struts-layout:struts-layout:1.2@jar",
    "struts-menu:struts-menu:2.4.2@jar",
    "struts:struts:1.2.7@jar",
    "taglibs:standard:1.1.1@jar",
    "xerces:xerces:2.4.0@jar"
]
  List tlds = [
 "struts:struts-tiles:1.2.7@tld",
     "struts:struts-bean:1.2.7@tld",
     "struts:struts-bean-el:1.2.7@tld",
     "struts:struts-logic:1.2.7@tld",
     "struts:struts-logic-el:1.2.7@tld",
     "struts:struts-html:1.2.7@tld",
     "struts:struts-html-el:1.2.7@tld",
     ...
]
   configurations{
 tld
}
  dependencies {
    compile runTime
    tld tlds
}
    war{
 from(configurations.tlds){
  into("WEB-INF/tld")
 }
}

cheers, René


(Stéphane Bury) #3

Thank’s René,

It work now, but there is just one typo error on your example. It fail on this line:

from(configurations.tlds){

because should be

from(configurations.tld){

One thing I don’t understand is that the first time I start the script it keep some things in cache then produce the same output as before modification.

I have to clear my build folder to make it work because it say’s that nothing changed so he don’t rebuild the war ! Strange, no ?

(I think I will upgrade soon my gradle 1.0 M6 to the last available version !)

Thank’s a lot, Fonzy.