AbstractCompile.destinationDir property has been deprecated

Hi there, since I got the warning on title, I don’t know how I should update this deprecated code:

  new File(destinationDir, "${rootProject.name}.build.version").text = "${version}"

I should be using ‘destinationDirectory’ instead, but it is not a drop-in replacement, at least in this use case.

For context, the full block looks like this:

compileJava.doLast {
   def buildDate = new Date().format('yyyy-MM-dd HHmm')
   println "Writing ${rootProject.name}.build.date: " + buildDate
   new File(destinationDir, "${rootProject.name}.build.date").text = buildDate
   new File(destinationDir, "${rootProject.name}.build.version").text = "${version}"

The replacement would be

destinationDirectory.file("${rootProject.name}.build.date").get().asFile.text = buildDate

But it might anyway be a better idea to generate these files as resources, not as compilation result.
For example by having them in src/main/resources with placeholders and using expand on the processResources task to fill in the placeholders.

1 Like

I’ve searched the documentation for placeholder resources, but couldn’t find the topic you are referring to. Could you please send me a link? Thanks!

This is about managing resources: Building Java & JVM projects
which also links to Working With Files which describes some of the possibilities you have also for the processResources task like for example using expand.