How to put all build files to one folder

I’m working on web app project.

I come up with idea that I don’t need jar or war.

Basically my project exposes API over http and websocktes. Nobody can use it as a dependency. So I don’t see any reason to use jar. I know it may sounds weird, but I want to test this idea.

I’m using embedded jetty and I run my project just as java -java app.jar app.conf.

I tried to unzip my jar file and run it as java -cp .:lib/* com.example.Main app.conf and it did worked.

So I want to put all files that gradle puts to jar file to folder without archiving it. After that I can just rsync folder to server or copy it to docker container.

What is the simplest way to do this with gradle?

I can probably do it by using jar.eachFile, just copy files to folder.

jar.eachFile {
    println it

Maybe there is an easiest way just with one Copy task.

So, you want what’s often called an exploded jar. For that, you can use the copy spec that already exists for the jar task (with) in a Copy task.

task explodedJar(type: Copy) {
    with jar
    into "${buildDir}/exploded"

@jjustinic yeah, you’ve got the idea.

Just one more thing, how to add libraries to exploded folder as well?

I’ve tried this

task explodedJar(type: Copy) {
    println 'hello'
    into "${buildDir}/exploded"
    into("${buildDir}/exploded/lib") {
        from configurations.compile
explodedJar.dependsOn jar

It almost worked, all jars in the lib folder, but it made a lot of unwanted folders:

Also, I don’t need to make jar file now, so is that possible to exclude this task from ./gradlew build?

There’s a slight difference between into(...) and into(...) {...} here. The former configures the root copy spec, and the latter configures a child copy spec. The child copy spec into is relative to the root copy spec into. So, you’re copying configurations.compile into ${buildDir}/exploded/${buildDir}/exploded/lib.

You’d also typically want runtimeClasspath (or runtimeClasspath if you’re using recent versions and want to get off the deprecated configurations) over compile.

The easiest way to stop the jar task from running is to just disable it.

Together, it could look like this:

task explodedJar(type: Copy) {
    with jar
    into "${buildDir}/exploded"
    into('lib') {
        from configurations.runtimeClasspath

jar.enabled = false
assemble.dependsOn explodedJar

Awesome, it’s works.

Thank you.