How to use gradle Tar tasks in custom plugin?


(Andy) #1

We have custom gradle plugin with custom task that checkouts files from SVN and make install and uninstall (for our DB) structure in build directory. Plugin have self implemented function, that makes several tbz archives (in loop per every script type) at the end of custom build task. How can i refactor this plugin, so it will use standart Tar task?

old code -

    WhsUtils.CreateTarBZ(project.buildDir.getAbsolutePath() + RELEASE_PATH + "${scriptType}/",
            project.buildDir.getAbsolutePath() + RELEASE_PATH + "${releaseNumber}-${scriptType}.tbz")

new code, that create Tar tasks at runtimeā€¦

        Tar tar = project.tasks.create("${releaseNumber}-${scriptType}-tartask", Tar)
        tar.configure {
            compression = Compression.BZIP2
            extension = 'tbz'
            baseName = "${releaseNumber}-${scriptType}-tartask"
            destinationDir = new File(project.buildDir.path + '/distribution')
            from(project.buildDir.getAbsolutePath() + RELEASE_PATH + "${scriptType}/")
        }
        tar.execute()

Is that code OK?