Do you want pre-process Freemarker templates at Gradle compile time? I prepared a primitive tool, based on several tutorials. This tool join Freemarker framework to your build process. I bring a WatchTask, a task, which monitor templates files and compile it, when change is detected.
The first purpose of this tool was to process FTL templates at compile time. So for example, in a Web project, you need to organize HTML code. Easiest way is to organize them in templates. Later you need process templates to gain final HTML code. Usually you process them at runtime. Runtime processing take some resources. To boost performance people start thinking about caching. But there exist simpler solution, the compile time preprocessor.
- Freemarker 2.3.23
- Guava 19.0
- Copy webResources.gradle to your build.gradle
- Apply Gradle script to your build process. Put this code to end of build.gradle.
apply from: "webResources.gradle"
processResources.dependsOn monitorWebResources
- Configure source dirs at webResources.gradle file
- Start monitoring of files
gradlew monitorTemplates -t
- Edit FTL templates
- Final files are copied to outputDir
Simple put next command to your build.gradle:
processResources.dependsOn monitorWebResources
Preprocessor will start at process-resources phase.
Sure, just replace the Freemarker. Some template frameworks focused on Android.
- Inspired by article.
- More details about Gradle continuous build.
- About custom tasks and how to watch changes. More.
- Nice article why dont use JSP.
- Nice similar tool.