1

Gretty を使用して Web アプリケーションを実行していますgradle appRun。また、Gradle Asset Pipeline プラグインを使用して、Less ファイルを CSS にコンパイルしています。

Less ファイルを変更すると、それが自動的にコンパイルされ、CSS がインプレース Web アプリにコピーされるように、Gretty の Fast reload 機能と統合したいと考えています。

ファイルにGrettyのonScanFilesChanged設定を使用してソリューションを実装しましたbuild.gradle

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()
        }
    } 
}

ファイルにそれほど多くのコードを含まない、これを行うためのより適切な方法はありbuild.gradleますか?

4

1 に答える 1