I'm using Gretty to run my web application via gradle appRun
. I'm also using the Gradle Asset Pipeline plugin to compile my Less files to CSS.
I want to integrate with Gretty's Fast reload feature so that when I change a Less file, it automatically compiles it and copies the CSS to the in-place web-app.
I have implemented a solution using Gretty's onScanFilesChanged
setting in my build.gradle
file:
buildscript {
dependencies {
classpath 'org.akhikhl.gretty:gretty:1.2.4'
classpath 'com.bertramlabs.plugins:asset-pipeline-gradle:2.7.0'
classpath 'com.bertramlabs.plugins:less-asset-pipeline:2.7.0'
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'war'
apply plugin: 'org.akhikhl.gretty'
apply plugin: 'com.bertramlabs.asset-pipeline'
dependencies {
// ...
}
assets {
excludes = ['bootstrap/**']
}
war.dependsOn assetCompile
gretty {
servletContainer = 'tomcat8'
enableNaming = true
contextPath = '/'
// This affects the war task as well
webappCopy {
from 'build/assets', { into 'stylesheet' }
}
afterEvaluate {
prepareInplaceWebAppFolder.dependsOn assetCompile
}
scanDir "src/assets"
fastReload "src/assets"
onScanFilesChanged { List<String> files ->
if (files.findAll { it.endsWith ".less" }.size() > 0) {
assetCompile.compile()
}
}
}
Is there a neater way to do this that doesn't involve so much code in the build.gradle
file?