twbbas
twbbas

Reputation: 447

Create a FAT source-only jar using Gradle

I need to create a jar that includes dependencies (a FAT jar) using Gradle.

The catch: the jar needs to only include the straight .groovy files... no .class files.

I've seen the way to do it from the Gradle cookbook: http://docs.codehaus.org/display/GRADLE/Cookbook#Cookbook-Creatingafatjar

and the One-Jar plugin: https://github.com/rholder/gradle-one-jar

but both ways involved using the compiled .class files instead of the actual source .groovy files. Also, I don't need this jar to be runnable. I just need to be able to reference my .groovy scripts and have the dependencies already be there for them.

Is this possible?

Upvotes: 2

Views: 520

Answers (1)

atschabu
atschabu

Reputation: 91

I'm not sure if you even need a .jar file, or a .zip would suffice as it would be confusing to distribute source in a .jar. But independently of what you need, the Zip task is what you want:

task('fatJar', type: Zip) {
    extension = 'jar' // overriding default value: 'zip'
    classifier = 'fat' // alternatively you can set basename or appending

    from(sourceSets.main.allGroovy) // will fail if the groovy plugin isn't applied
    from(configurations.runtime) // this includes all your jars needed on runtime
}

Now this is an extremely simple example which will create a file called [projectName]-[version]-fat.jar within build/distributions/ with all your jars in the root of the zip and the groovy source files next to them. You might want to take a look at the documentation of the Gradle Zip task for more options.

Upvotes: 3

Related Questions