Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I define two different 'distribution' tasks in gradle?

Tags:

gradle

The normal behavior of the distTar and distZip tasks from the application plugin in gradle seems to be to copy the contents of src/dist into the zip and tar files, but I have a subfolder in src/dist that I want to exclude from the default distribution, and include it for a new (extended) task, possibly to be called distZipWithJRE.

I have been able to exclude this folder in the default task as follows:

distributions.main {
    contents {
        from('build/config/main') {
            into('config')
        }

        from('../src/dist') {
            exclude('jre')
        }
    }
}

How can I define a second task that behaves just like the original (unmodified) task?

like image 836
Mirrana Avatar asked Jan 09 '23 07:01

Mirrana


2 Answers

Using Gradle 4.8 I had to tweak the answer to use 'with' from CopySpec instead

distributions {
    zipWithJRE {
        baseName = 'zipWithJRE'
        contents {
            with distributions.main.contents
        }
    }
}
like image 182
Ross Perston Avatar answered Mar 01 '23 23:03

Ross Perston


It seems that what you're looking for is in the docs. You need to leave current settings as is and for zipWithJRE create and configure custom distribution:

distributions {
    zipWithJRE {
        baseName = 'zipWithJRE'
        contents {
           from { distributions.main.contents }
        }
    }
}
like image 34
Opal Avatar answered Mar 01 '23 23:03

Opal