简体   繁体   中英

gradle spring boot project: How to rename files in war?

I am building a web application using Spring Boot. I would like to change some names of WEB-INF/lib/*.jars in the final.

If I understand the docs correctly, this should work using the "rename" method of the bootWar task (a subclass of the standard war task) which is supplied by the spring-boot-gradle-plugin.

However the "rename" method is never executed at all, ie if I add this to my build.gradle:

   bootWar {
      rename { name ->
        println "***** " + name
        name
    }

then nothing gets printed at all. The "rename" method overloads that take an original pattern and a replacement pattern do not work either.

I tried it with an example project, and it did not work there either:

  • use Spring Initializr with "Web" dependency to create a new project
  • change the apply plugin: 'java' to apply plugin: 'war'
  • add the bootWar configuration from above

You need to call rename method on the bootWar.rootSpec as follows:

bootWar {
    rootSpec.rename { name ->
        println "***** " + name
        name
    }
}

Then you will have hand to rename the libs you need:

> Task :bootWar
***** MANIFEST.MF   
***** spring-boot-starter-web-2.0.4.RELEASE.jar 
***** spring-boot-starter-aop-2.0.4.RELEASE.jar 
***** spring-boot-starter-2.0.4.RELEASE.jar
( ...)

I don't know the reasons for that, but the rename closure from War task will be only applied to resources located under your project's src/main/webapp directory, not other resources (like dependencies). You can confirm this by creating a dummy resource src/main/webapp/foo.txt and execute your test script :

$ ./gradlew bootWar

> Task :bootWar
***** foo.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM