Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the right way to integrate Grunt into a Spring/Gradle build?

I have a Spring Boot project that is built with Gradle. All my front-end code lives under src/main/resources/static. This also includes my bower_components, node_modules (for Grunt tasks), etc.

Right now, I have my main Gradle build script exec the Grunt build, which concatenates/minifies all my JavaScript, and they go under src/main/resources/static/dist. Then, when processResources gets executed in Gradle, the entire src/main/resources/static/dist gets copied to the build directory. This doesn't seem right to me - the only stuff that should end up in the build directory are the concatenated/minified JS, CSS, HTML and images.

I've searched high and low but haven't found any clear direction here. Is there a best practice for building a project in this way?

like image 658
Joe Attardi Avatar asked Feb 23 '14 22:02

Joe Attardi


People also ask

What is grunt and Gradle?

Gradle and Grunt are primarily classified as "Java Build" and "JS Build Tools / JS Task Runners" tools respectively. "Flexibility" is the primary reason why developers consider Gradle over the competitors, whereas "Configuration " was stated as the key factor in picking Grunt.

What does Gradle build do?

Gradle is a general-purpose build tool Gradle makes it easy to build common types of project — say Java libraries — by adding a layer of conventions and prebuilt functionality through plugins. You can even create and publish custom plugins to encapsulate your own conventions and build functionality.


1 Answers

Files generated as part of the build shouldn't go into src, but somewhere under the build directory (say build/grunt). What's left is to include them in archives as necessary. For example:

war.dependsOn(grunt)
war {
    from "build/grunt"
}

Or, if the Grunt task declares it outputs:

war {
    from grunt
}
like image 177
Peter Niederwieser Avatar answered Nov 15 '22 06:11

Peter Niederwieser