Gradle war task: how configure to ignore or remove unnecessary directories?

(Manuel Jordan) #1

I am working with:

  • Spring Framework
  • Thymeleaf
  • Gradle

with multimodules

For testing purposes between modules is mandatory have the html files and js css files within the src/main/resources (and not within src/main/webapp/WEB-INF how is expected)

Thus as follows

public SpringResourceTemplateResolver templateResolver() {
	SpringResourceTemplateResolver templateResolver = new SpringResourceTemplateResolver();
	return templateResolver;

To generate the .war file I use:

apply plugin: 'war'

project(':thymeleaf-02-web') {

	description 'Web (HTML, JS, CSS)'
	dependencies {
				compile project("$it")

    //webAppDirName = 'src/main/webapp'
    webAppDirName = 'src/main/resources' //<---  mandatory now
	war {
		baseName = warBaseName


The .war generated and deployed works in runtime, but it has the following structure:

enter image description here

It has twice the static and templates directories. I have confirmed the following:

  • thymeleaf-02/templates is not necessary (so, is removed manually)
  • thymeleaf-02/WEB-INF/classes/static is not necessary (so, is removed manually)

Thus how in the war task can be configured to remove or avoid the unnecessary creation or generation of these two directory/paths when the .war be generated?