Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle - change main distribution - get rid of bin and lib folders

Tags:

java

gradle

I have a Gradle build with application plugin applied. Application plugin also applies distribution plugin and creates default main distribution, which will place startup scripts in bin folder, and dependencies in lib.

Now I want to completely remove that default behavior and have my own distribution but with the same name main. To be more precise I don't want bin and lib folders and want my custom content.

I know I can easily define a new distribution like

distributions {
    my {
        // my configuration here
    }
}

so I can produce desired distribution via myDistZip for example.

But I want to change exactly main distribution so I will be able to produce archive via simple distZip (or distTar).

I tried to remove main distribution (via distributions.remove(distributions.main)) and create new one

distributions {
    main {
        // my configuration here
    }
}

but that fails with

Cannot add task ':distZip' as a task with that name already exists.

I guess this is simply because Gradle creates distZip tasks for every new distribution, so it was trying to do that for new main as well, however distZip task was already created during plugin application.

So is there any way to change main distribution to get rid of bin and lib folders?

Gradle: 3.5

like image 423
xzt Avatar asked Oct 29 '22 08:10

xzt


1 Answers

But I want to change exactly main distribution so I will be able to produce archive via simple distZip (or distTar).

It seems like you don't have to change main distribution - the documentation for distribution plugin (added automatically by application plugin) notes that for each distribution, so you can use gradle myDistZip.

However it seems that you should be able to configure existing main distribution as well:

distributions {
  main {
    contents {
      // configure
    }
  }
}

While you can't reset existing values it seems, maybe you could use exclusions to not copy specific folders (see https://docs.gradle.org/current/javadoc/org/gradle/api/file/CopySpec.html)

like image 75
wasyl Avatar answered Nov 15 '22 05:11

wasyl