How to use `distributions` to copy a folder, not just single files?

Hi, I’ve spent about two hours reading gradle docs and making changes to my build file but I can’t figure this trivial thing out.

// build.gradle.kts

plugins { application }
repositories { ... }
dependencies { ... }
application { mainClass.set("...") }

distributions {
    main {
        contents {
            from("config")
        }
    }
}

When I run ./gradlew build I get a zip file with the following content:

app/bin/...
app/lib/...
app/one.json
app/two.json
app/three.json

but what I need is

app/bin/...
app/lib/...
app/config/one.json
app/config/two.json
app/config/three.json

How can I maintain the config folder?

You can use into to construct the destination directory structure.

contents {
    into("config") {
        from("config")
    }
}
1 Like

Alternatively:

from(".") {
    include("config/**")
}

Whatever you like better

1 Like

Thank you very much!

I had tried into next to from but not nested in that order.

I find the first solution more explicit and easier to decode in the future, still useful to know the second approach for when I encounter it :slight_smile: