DEV Community

Query Filter
Query Filter

Posted on

gradle-70

import groovy.json.JsonOutput

def generateManifest(String archivePath) {
    File archiveFile = new File(archivePath)

    // Ensure build/distributions directory exists
    File distributionsDir = file("$buildDir/distributions")
    if (!distributionsDir.exists()) {
        distributionsDir.mkdirs()
    }

    File manifestFile = new File(distributionsDir, "manifest.json")

    def manifestData = [
        archive_name : archiveFile.name,
        archive_path : archiveFile.absolutePath,
        archive_size : archiveFile.length(),
        project_name : project.name,
        version      : project.version.toString(),
        build_date   : new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(new Date())
    ]

    manifestFile.text = JsonOutput.prettyPrint(JsonOutput.toJson(manifestData))
    logger.lifecycle("Manifest successfully generated at: ${manifestFile.absolutePath}")
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)