Issue
I have simple web project with gradle and I wish to obtain gradle variable in thymeleaf template like:
Updated part of Thymeleaf template
<title>Simple project title v.: @myVar@-beta</title>
and in build.gradle I have this variable (updated after comments):
import org.apache.tools.ant.filters.ReplaceTokens
def myVar = "dev"
... minimized ...
war {
filter( ReplaceTokens, tokens: ['@myVar@': myVar])
}
where dev
- is a custom value from my build server which is passing by
gradle war -P myVar=122
.
How I can get it if this is possible?
Solution
You wont be able to do this. Well... not the way you are trying to. And then there is the thing that your code should not depend on the build tool.
What you should do instead is, get the build tool to inject the variable into your code.
I am sure your thymeleaf template is being copied from its location to some place else during build, at this point add a filter clause.
change
<title>Some title ${#myVar}</title>
to
<title>Some title @myVar@</title>
and then
import org.apache.tools.ant.filters.ReplaceTokens // dont forget this import
war {
filter(ReplaceTokens, tokens: [myVar: myVar])
}
Answered By - Anup Puranik Answer Checked By - Clifford M. (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.