Put build version in index.html


I’m looking for a way to put version of my build in index.html.

Is there any way to do this.

Let say I have some place: ${build.version} in my index.html and during build one of the task will replace this variable to my current version.

Do you know some easy way to do this? Maybe I should create task with java code to: read file, replace and save

Thank you

If you want to copy the origin index.html to another place an replace this ${buildVersion} token you can use the expand method:

task myCopy(type: Copy) {

from ‘src/main/webapp’

into ‘build/explodedWar’

// Substitute property references in files

expand(buildVersion: “${project.version}”) }

Another option would be to use the ReplaceToken. The DSL reference of the Copy task has the details: http://www.gradle.org/docs/current/dsl/org.gradle.api.tasks.Copy.html

If you want to change this in the original location of index.html (I wouldn’t recommend that) you can use SimpleTemplateEngine which is part of the groovy sdk.

hope that helps!

Thank you Rene. I will go this way.