I am using Gradle in my project. I have a task for doing some extra configuration with my war. I need to build a string to use in my task like, lets say I have:
task extraStuff{ doStuff 'org.springframework:spring-web:3.0.6.RELEASE@war' }
This works fine. What I need to do is define version (actually already defined in properties file) and use this in the task like:
springVersion=3.0.6.RELEASE task extraStuff{ doStuff 'org.springframework:spring-web:${springVersion}@war' }
My problem is spring version is not recognised as variable. So how can I pass it inside the string?
Gradle builds a script file for handling two things; one is projects and other is tasks. Every Gradle build represents one or more projects. A project represents a library JAR or a web application or it might represent a ZIP that is assembled from the JARs produced by other projects.
Try to use ./gradlew -Dorg. gradle. jvmargs=-Xmx16g wrapper , pay attention on -D , this marks the property to be passed to gradle and jvm. Using -P a property is passed as gradle project property.
If you're developing an Android APP using Gradle, you can declare a variable (i.e holding a dependency version) thanks to the keyword def
like below:
def version = '1.2' dependencies { compile "groupId:artifactId:${version}" }
Hope that helped!
I think the problem may lay on string literal delimiters:
groovy
so enclose it in single or double quotes (e.g. "3.0.6.RELEASE"
);Gstrings
are not parsed in single quotes strings (both single '...'
or triple '''...'''
ones) if i recall correctly;So the code will be:
springVersion = '3.0.6.RELEASE' //or with double quotes "..." task extraStuff{ doStuff "org.springframework:spring-web:${springVersion}@war" }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With