Gradle does not generate quoted string

I am trying to include a custom field in a BuildConfig containing the build date using this function:

 def getDate() { def date = new Date() def formattedDate = date.format('yyyyMMddHHmmss') return formattedDate } 

Then in defaultConfig I will put:

 buildConfigField "String", "BUILD_NUMBER", getDate() 

The problem is that the field created by Gradle is:

 public static final String BUILD_NUMBER = 20141108114911; 

which throws "The integer is too big", but I do not need Integer, I need a string!

I tried to explicitly replace def with String , tried getDate().toString , getDate() as String and "${getDate()}" and still did not refer to my string. I also tried to put the character as "-" in the middle of the date, it does not generate quotation marks, doing:

 public static final String BUILD_NUMBER = 20141108-114911; 

obviously makes no sense ...

I don’t think here without being familiar enough with Groovy and therefore not sure if there is another (working) way to “force” String.

+6
source share
1 answer

You need to add hidden quotes:

 buildConfigField "String", "BUILD_NUMBER", "\"${new Date().format('yyyyMMddHHmmss')}\"" 
+19
source

Source: https://habr.com/ru/post/977914/


All Articles