Skip to content

Latest commit

 

History

History
91 lines (62 loc) · 1.66 KB

README.md

File metadata and controls

91 lines (62 loc) · 1.66 KB

Gradle template plugin

This Gradle plugin creates tasks that fill templates. The plugin uses the SimpleTemplateEngine.

How To Use

Applying the plugin

Edit build.gradle file to apply the plugin:

plugins {
  id 'io.github.rkotkiewicz.template' version '1.0.0'
}

Configuration

Configure the plugin by adding template section in build.gradle:

template {    
  // use `create` to add task
  // you can create many tasks
  create("templateName") {
      
    // 'from': File | Directory  
    // mandatory  
    from.set(file("$projectDir/templates"))
      
    // 'into': Directory
    // optional
    // default = "$buildDir/taskNamePrefix" 
    into.set(file("$buildDir/outputDir"))

    // binding is map: String -> Any
    // optional, but you want to set it
    binding([b0: "value0", b1: [1, 2, 42]])
  }
}

The configuration will create task with name: fillTemplateNameTemplate.

The b0: "value0", b1: [1, 2, 42] bindings will be applied to all template files from "$projectDir/templates".

Result will be saved into "$buildDir/outputDir".

Example Usage

template file

The template file is in: $projectDir/src/file.txt

with content:

pi = $pi

configuration

template {
    
  create("pi") {
    from.set(file("$projectDir/src/file.txt"))
    binding([pi: 3.14159265359])
  }
}

filling template

To generate template run task:

./gradlew fillPiTemplate

result

The result with content:

pi = 3.14159265359

will be saved into "$buildDir/template/pi/file.txt".