gradle tar task not executed

Viewed 10231

I am writing a Gradle build for a non-java project for assembling existing directories and tar archives into a .tar.gz The tar task skips if I use the definition like so:

task archive(dependsOn: 'initArchive',type: Tar) << {
    baseName = project.Name
    destinationDir = new File(project.buildDir.path+'/installer')
    compression = Compression.GZIP
    from (archiveDir)
    doLast{
        checksum(archivePath)
    }
}

here's the console output

:jenkins-maven-sonar:archive
Skipping task ':jenkins-maven-sonar:archive' as it has no source files.
:jenkins-maven-sonar:archive UP-TO-DATE

BUILD SUCCESSFUL

Total time: 9.056 secs

When I try to use tar task as a method it fails complaining cannot find method

task archive(dependsOn: 'initArchive') << {
    tar{
    baseName = project.Name
    destinationDir = new File(project.buildDir.path+'/installer')
    compression = Compression.GZIP
    from (archiveDir)
    doLast{
        checksum(archivePath)
    }
    }
}

FAILURE: Build failed with an exception.

* Where:
Build file '/home/anadi/Code/da-ci-installers/build.gradle' line: 29

* What went wrong:
Execution failed for task ':jenkins-maven-sonar:archive'.
> Could not find method tar() for arguments [build_6a2bckppv2tk8qodr6lkg5tqft$_run_closure3_closure5_closure7@4a5f634c] on task ':jenkins-maven-sonar:archive'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output.

BUILD FAILED

Total time: 8.749 secs

Can we run the tar task in same way as Gradle allows running copy? In the same build I have a block like follows and I want to know if tar can used in the same way

            copy {
                project.logger.info("Copying bundle :: "+bundle[x])
                from(rootProject.projectDir.path+"/3rd-party-tools/"+bundle[x]) {
                    include '**/*.*'
                }
                into(archiveDir)
           }

if not how to make sure my build does not "skip tar" task if using the first form described above.

2 Answers
Related