Last active
February 19, 2016 12:23
-
-
Save Bellfalasch/98c47044b56e8662b791 to your computer and use it in GitHub Desktop.
Example Gradle settings that minifies JS and CSS into all.js and main.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
buildscript { | |
repositories { | |
mavenLocal() | |
jcenter() | |
maven { | |
url 'http://repo.enonic.net/public' | |
} | |
} | |
dependencies { | |
classpath "com.enonic.xp:gradle-plugin:${xpVersion}" // Needed for EXP to work | |
classpath 'com.eriwen:gradle-js-plugin:1.12.1' | |
classpath 'com.eriwen:gradle-css-plugin:1.11.1' | |
} | |
} | |
repositories { | |
mavenCentral() | |
} | |
apply plugin: 'com.enonic.xp.app' // For EXP to work | |
apply plugin: 'maven' | |
apply plugin: 'maven-publish' | |
apply plugin: 'js' // eriwen plugin for minification of js | |
apply plugin: 'css' // eriwen plugin for minification of css | |
// Settings for our XP app: | |
app { | |
name = project.appName // The technical name that will be used by EXP | |
displayName = project.displayName // Human readable name, used in App Manager | |
vendorName = 'Enonic AS' | |
vendorUrl = 'http://enonic.com' | |
} | |
dependencies { | |
compile "com.enonic.xp:core-api:${xpVersion}" | |
compile "com.enonic.xp:portal-api:${xpVersion}" | |
include "com.enonic.xp:lib-content:${xpVersion}" | |
include "com.enonic.xp:lib-portal:${xpVersion}" | |
include "com.enonic.xp:lib-thymeleaf:${xpVersion}" | |
include 'com.enonic.lib:util:1.0.0' // Add Util Lib on "gradle deploy" | |
include 'com.enonic.lib:menu:1.1.1' // Add Menu Lib | |
} | |
repositories { | |
mavenLocal() | |
jcenter() | |
maven { | |
url 'http://repo.enonic.net/public' | |
} | |
} | |
///////////////////////////////////////////////////// | |
// JAVASCRIPT | |
///////////////////////////////////////////////////// | |
// Declare your sources, used later in "combineJs". | |
javascript.source { | |
custom { | |
js { | |
srcDir "src/main/resources/site/assets/js" | |
include "*.js" | |
//exclude "*.min.js" | |
} | |
} | |
util { | |
js { | |
srcDir "src/main/resources/site/assets/js/lib/util" | |
include "*.js" | |
} | |
} | |
vendor { | |
js { | |
srcDir "src/main/resources/site/assets/js/vendor" | |
include "*.js" | |
} | |
} | |
jquery { | |
js { | |
srcDir "src/main/resources/site/assets/js/vendor/jquery" | |
include "*.js" | |
// include "**/*.js" // Use this to look in all subfolders and find all .js files. | |
} | |
} | |
} | |
jshint { | |
tasks.jshint.source = javascript.source.custom.js.files + javascript.source.util.js.files | |
tasks.jshint.dest = file("${buildDir}/jshint.out") | |
tasks.jshint.reporter = 'checkstyle' | |
tasks.jshint.outputToStdOut = true | |
} | |
minifyJs { | |
source = javascript.source.custom.js.files | |
dest = file("${buildDir}/resources/main/site/assets/js/custom.min.js") | |
closure { | |
warningLevel = 'QUIET' | |
} | |
} | |
// Combine JS - order is very important! Jquery first, then vendor, then custom (this App's own JS). | |
combineJs { | |
source = javascript.source.jquery.js.files + javascript.source.vendor.js.files + javascript.source.util.js.files + javascript.source.custom.js.files | |
dest = file("${buildDir}/resources/main/site/assets/js/all.js") | |
} | |
requireJs { | |
source = javascript.source.custom.js.files | |
dest = file("${buildDir}/resources/main/site/assets/js/main-built.js") | |
requirejs.buildprofile = new File('src/main/resources/site/assets/js/build.js') | |
} | |
///////////////////////////////////////////////////// | |
// CSS | |
///////////////////////////////////////////////////// | |
minifyCss { | |
source = "${buildDir}/resources/main/site/assets/css/tmp/main.css" | |
dest = "${buildDir}/resources/main/site/assets/css/tmp/main-min.css" | |
} | |
///////////////////////////////////////////////////// | |
// BUILD TIME! | |
///////////////////////////////////////////////////// | |
// Call our scripts | |
jar.dependsOn += combineJs | |
jar.dependsOn += minifyCss | |
// Hack to circumvent problem in rb-inotify:0.9.7 that broke compass compile | |
configurations.all { resolutionStrategy.force 'rubygems:rb-inotify:0.9.5' } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment