Add generated files with gradle before creating WAR

During development, we use javascript and CSS files that have not been reduced. But they must be minimized (with the help of a unicompressor) when a production war is being built. So, I want to replace the original javascript and CSS files with miniature ones. The structure of the project is as follows (nothing special):

+ webapp
|-- js
|-- css
...

I want to do the following: before WAR creates Gradle, I want to minimize the above files with yuicompressor and want them to be packaged in WAR.

What I have done so far is to run the task before creating the WAR, which minimizes the files:

war {
   it.dependsOn minifyJavaScript
}

The minifyJavaScript task accepts all files in the webapp / js folder, minimizes them and saves them in the $ {buildDir} / js directory. The only thing I could not work for was that these files are packaged in WAR. I tried to configure sourceSets, but I got an error from Gradle:

apply plugin: 'java'

...
sourceSets {
    main {
        webapp {
            srcDir "${buildDir}/js"
        }
    }
}

Error: Unsupported Gradle DSL Method Found: 'sourceSets ()'

I also tried to include files using:

war {
   it.dependsOn minifyJavaScript
   include ${buildDir}/js
}

The problem with this solution is that the WAR contains only mini files.

So, is there a way to tell Gradle to add the path $ {buildDir} / js during the creation of the WAR? Or is there a better / easier way to include mini files?

+4
source share
2 answers

This is harder than I thought:

war {
    it.dependsOn minifyJavaScript
    exclude "js"
    from( "${buildDir}/js", {
        into 'js'
    })
}

JS . , js ( WAR).

+6

src/main/webapp. .

0

All Articles