javascript - Add generated files with gradle before WAR creation - Stack Overflow

During development we are using javascript and CSS files that are not minified. But they have to be min

During development we are using javascript and CSS files that are not minified. But they have to be minified (with yuipressor) when the production war is built. So, I want to replace the original javascript and CSS files with the minified ones. The project structure looks as follows (nothing special):

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

What I want to do is: before the WAR is created by Gradle, I want to minify the above mentioned files with yuipressor and want them to be packed in the WAR.

What I did so far is to run a task before the WAR is created, which minifies the files:

war {
   it.dependsOn minifyJavaScript
}

The task minifyJavaScript takes all files in the webapp/js folder, minifies them and store them in the ${buildDir}/js directory. The only thing I couldn't get to work is that these files are packed into the WAR. I tried to adjust the 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 the files with with:

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

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

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

During development we are using javascript and CSS files that are not minified. But they have to be minified (with yuipressor) when the production war is built. So, I want to replace the original javascript and CSS files with the minified ones. The project structure looks as follows (nothing special):

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

What I want to do is: before the WAR is created by Gradle, I want to minify the above mentioned files with yuipressor and want them to be packed in the WAR.

What I did so far is to run a task before the WAR is created, which minifies the files:

war {
   it.dependsOn minifyJavaScript
}

The task minifyJavaScript takes all files in the webapp/js folder, minifies them and store them in the ${buildDir}/js directory. The only thing I couldn't get to work is that these files are packed into the WAR. I tried to adjust the 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 the files with with:

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

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

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

Share Improve this question edited Sep 10, 2014 at 14:04 Daniel asked Sep 10, 2014 at 9:57 DanielDaniel 9151 gold badge8 silver badges20 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

It is harder than I thought:

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

I've to exclude the not minified JS files and than include the minified ones. The original files have to be excluded, otherwise the files in the js directory are duplicated (in the created WAR file).

Put the files under src/main/webapp directory. The will picked up automatically from this location.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745545895a4632337.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信