eekboom
eekboom

Reputation: 5802

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, i.e. 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:

Upvotes: 2

Views: 2418

Answers (1)

M.Ricciuti
M.Ricciuti

Reputation: 12086

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.txtand execute your test script :

$ ./gradlew bootWar

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

Upvotes: 2

Related Questions