Home > Software engineering >  Correct way to convert Zip task `archiveFile` to an absolute path?
Correct way to convert Zip task `archiveFile` to an absolute path?

Time:03-15

I'm trying to remove usages of deprecated stuff from my Gradle scripts. I noticed archivePath is supposed to be replaced by archiveFile.

What's the "right" way to convert archiveFile to an absolute path?

Here's my Gradle task:

task buildZip(type: Zip){
  ...
  doLast {
    //  ZipUtil.normaliseZipDates(archivePath.absolutePath)
    ZipUtil.normaliseZipDates(archiveFile.get().asFile.absolutePath)
  }

normaliseZipDates takes a String, I can't just pass it archiveFile and archiveFile.absolutePath gives "No such property: absolutePath".

At the moment, as shown above, I'm using archiveFile.get().asFile.absolutePath but that seems crazy verbose - what's the correct way to this?

Context: Using Gradle 6.9 at the moment, soon upgrading to to 7.x.

CodePudding user response:

println archiveFile.get().toString() also seems to give full file path -

> Task :buildZip
/Users/xyz/Projects/gradle-scala/build/distributions/gradle-scala-1.0-SNAPSHOT.zip

but I would recommend to stick with archiveFile.get().asFile.absolutePath

  • Related