DEV Community

Query Filter
Query Filter

Posted on

gradle-67

// Task to inspect the generated TAR.GZ archive
tasks.register('inspectDistTar') {
    dependsOn tasks.distTar

    doLast {
        // Retrieve the generated tar archive file from the distTar task
        File tarFile = tasks.distTar.archiveFile.get().asFile

        if (!tarFile.exists()) {
            println "Archive file does not exist: ${tarFile.absolutePath}"
            return
        }

        println "\n========================================================"
        println " ARCHIVE INSPECTION SUMMARY"
        println "========================================================"
        println "Location : ${tarFile.absolutePath}"
        println "Size     : ${String.format('%.2f', tarFile.length() / (1024.0 * 1024.0))} MB (${tarFile.length()} bytes)"
        println "--------------------------------------------------------"
        println "Contents :"

        // Wrap tarball in tarTree to iterate and list internal files
        tarTree(tarFile).visit { details ->
            if (!details.isDirectory()) {
                println "  - ${details.relativePath}"
            }
        }
        println "========================================================\n"
    }
}

// Automatically execute inspection right after distTar completes
tasks.distTar.finalizedBy tasks.inspectDistTar
Enter fullscreen mode Exit fullscreen mode

Top comments (0)