How do I pick and choose what to include in the application plugin distZip task?

How do I pick and choose what to include in the application plugin distZip task?

Here is what I tried to do but it isn’t working and I am unsure how to debug something like this:

mainClassName = 'webdriver.test.BasicHttpServer'
  task createSite {
    // want to include more than just a single directory
    //def site = file("$buildDir/site")
    FileTree site = fileTree(dir: '$buildDir/site')
    site.include 'startWeb.bat'
    site.include ''
    site.exclude '**/*.log'
      outputs.dir site
  applicationDistribution.from( createSite ) {
    into "site"

There are several problems with this code. Assuming the ‘createSite’ task writes into the ‘build/site’ directory, I’d do something like:

task createSite {
    outputs.dir "$buildDir/site"
    doLast { /* do the work */ }
  applicationDistribution {
    into("site") {
        from createSite // don't quite understand what you are trying to include/exclude

Thanks for your help/ideas. I got it working with this code:

mainClassName = 'webdriver.test.BasicHttpServer'
  task copySiteFiles(type: Copy) {
    def fileDir = new File('build/site')
    from 'site'
    into fileDir
    outputs.dir fileDir
  applicationDistribution.from( copySiteFiles ) {
    into "site"

Now, the only problem I have left is that I don’t know how to get the “application” plugin to include a script file that I define. The plugin is auto-generating a .bat and a .sh that I did not create. Any idea how to control that?

Why do you first copy the files, instead of simply including them with ‘applicationDistribution.from(“build/site”)’? In the same manner, you can add any other files to the distribution. You should be able to prevent the default scripts from being added with something like ‘applicationDistribution.exclude("**/bin/${applicationName}*")’. As far as I know, it isn’t currently possible to customize the default scripts.

You write “As far as I know, it isn’t currently possible to customize the default scripts.” Is it possible to coerce the application plugin to make a standard executable jar (with external dependencies, not like this ?

I’m a bit lost with the Application-plugin documentation. What I want is the following:

assume $projectDir is my project root

1.) have Gradle create + populate a $projectDir/dist directory containing the following: 2.) my projects’ jar 3.) a copy of all required jars 4.) a copy of all documentation from the $projectDir/doc 5.) a copy of my licence.txt, usually from $projectDir/licence.txt 6.) a copy of from $projectDir/ 7.) a copy of other files (e.g. openIssues, resources, tutorials)

From the documentation of the Application plugin, I see the

task createDocs {
    def docs = file("$buildDir/docs")
    outputs.dir docs
    doLast {
        new File(docs, "readme.txt").write("Read me!")
  applicationDistribution.from(createDocs) {
    into "docs"

I’d like a “createDist” target/action to create all the things 1-7…

thx, Gernot

Hi Gernot

This is pretty much what the application plugin does already. Just do this

apply plugin:'application'

Now, when you run

./gradlew installApp

the plugin will do 1, 2 and 3 and put them in build/install

If 4,5,6 & 7 are static files then just place them in src/dist and they will be taken care of too.

The example you have shown is for resources that are dynamically created by the build. For example, if your documentation is in markdown and you want to generate HTML to put in your install, then you need to define a task to do that and ask the application plugin to use it when creating an applicationDistribution as shown in the example.

When I copy my static files with:

applicationDistribution.from( files('', 'license.txt', 'pdfutil-logo.jpg')) {
    into( buildDir )

gradle copies the absolute path of these files, creating a structure like


I need them to reside in the root (buildDir) without their original path…