Take the 2-minute tour ×

I have a small Java/Gradle project. I'm using the Application plugin to create a zip distribution (using the distZip task). Using the standard configuration I get the following directories in my zip file:

/bin - The scripts to start the application go in here
/lib - Contains my project code in a JAR file and all dependency JAR files.

The trouble is that I would like a third directory: /conf where I can put my configuration files (instead of having them packaged inside my application JAR file.

I imagine that this is a pretty common requirement because things like log4j.xml and hibernate.properties would be better placed outside the JAR file. I just can't figure out how I can customise the behavior of the Application plugin to do this however.

share|improve this question
add comment

3 Answers

up vote 7 down vote accepted

I revisited this problem several months later and I finally have an elegant solution. The following code should be added to the gradle file:

distZip {
    into(project.name) {
        from '.'
        include 'conf/*'

This adds an additional include to the distZip task. This copies the "conf" directory (including contents) into the Zip distribution.

The generated zip file contains a single directory which is the same as the project name. This is why the "into" part is required.

share|improve this answer
add comment

Actually, create a dist dir under the src dir in your project. Anything in this dir is copied by the application plugin (under applicationDistribution) when installApp or distZip is run.

Or edit applicationDistribution to do other things, if a simple copy is not enough.

share|improve this answer
add comment

I am not sure whether you can customize the application plugin, I have never used it. There is however other ways to achieve what you want to achieve.

You may create a /conf directory like this:

confDir = new File("$buildDir/conf")

You can then copy the files you need into this directory like this:

task copyConfFiles(type: Copy) {
   from _wherever your files reside_
   into confDir
   include('**/*.properties') // your configuration files 

You may then hook this copy task into the process like this:

distZip.dependsOn copyConfFiles

And last if you do not want your configurations in the final zip, you can do this:

distZip {
   exclude('**/*.properties') // your configuration files

Again, there might be a better way. This is a way.

share|improve this answer
Thanks for the suggestion! I've tried this out and I now have the "conf" directory (with config files) in my build directory. Unfortunately I don't see a way to get this new directory included in the generated Zip file. There doesn't seem to be a Zip file "staging" area that I can manipulate and there also doesn't seem to be any way to tell the distZip plugin to include additional directories. Any ideas? –  James Blewitt Apr 26 '11 at 8:17
OK, it seems that you can in fact generate a "staging" area. The "install" task generates a directory which contains all the files in the Zip. I could generate this, then add my "conf" directory to it and then zip it up by hand. I think that this will work, but it isn't elegant. –  James Blewitt Apr 26 '11 at 8:45
add comment

Your Answer


