Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cherry pick ZIP contents with Gradle Distribution plugin?

My Gradle build currently produces the following directory structure under a build dir in my project root:

myapp/
    src/
    build.gradle
    build/
        docs/
            groovydoc/* (all Groovydocs)
        libs/
            myapp-SNAPSHOT.jar
            myapp-SNAPSHOT-sources.jar
        reports/
            codenarc/
                main.html
        test-results/* (JUnit test results)

I would like to add the distribution plugin (or anything that accomplishes my goals, really) to have Gradle produce a ZIP file with the following directory structure:

myapp-SNAPSHOT-buildreport.zip/
    tests/
        (JUnit tests from build/test-results above)
    reports/
        main.html (CodeNarc report from build/reports/codenarc above)
    api/
        (Groovydocs from build/docs above)
    source/
        myapp-SNAPSHOT-sources.jar (from build/libs above)
    bin/
        myapp-SNAPSHOT.jar (from build/libs above)

After reading the plugin's documentation, I can't tell how to configure it to suit these needs. Its obvious that I need to run gradle distZip, but as to how to actually configure it to produce the desired directory structure, it doesn't seem to provide any documentation/examples. Any ideas?

Note: The JAR's version is obviously SNAPSHOT, and is passed into the Gradle build with a -Pversion=SNAPSHOT command-line argument.

like image 682
smeeb Avatar asked Sep 20 '14 16:09

smeeb


People also ask

What does Gradlew installDist do?

You can run gradle installDist to assemble the uncompressed distribution into $buildDir/install/${project.name} .

How do I create a zip file in Gradle?

In Gradle, zip files can be created by using 'type: zip' in the task. In the below example, from is the path of source folder which we want to zip. destinationDir is the path of the destination where the zip file is to be created. archiveName is the name of the zip file.

What is Gradle base plugin?

The Base Plugin provides some tasks and conventions that are common to most builds and adds a structure to the build that promotes consistency in how they are run.


1 Answers

I would probably not use the distribution plugin and instead just create a new custom Zip task. It would look something like this:

task buildreportZip(type: Zip, dependsOn: build) {
    classifier = 'buildreport'

    from('build/test-results') {
        into 'tests'
    }

    from('build/reports/codenarc') {
        into 'reports'
    }

    from('build/docs') {
        into 'api'
    }

    from(sourcesJar) { // or whatever you source jar task name is
        into 'source'
    }

    from(jar) {
        into 'bin'
    }
}
like image 200
Mark Vieira Avatar answered Sep 28 '22 01:09

Mark Vieira