I am using Gradle 1.3 and have it working for a small project. It creates the .JAR files exactly as I want them to. However, when I have it create a ZIP file using distZip
I didn't find any API for this plugin but you can find the full source code of the ApplicationPlugin in the github repository https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/groovy/org/gradle/api/plugins/ApplicationPlugin.groovy This plugin copys all references from "project.configurations.runtime" into the directory "lib". Therefore, you can edit the runtime classpath and exclude all non needed files. This should be possible by adding a new configuration and adding the dependencies that shouldnt be included to this new configuration. You probably want to add the excluded files to the run classpath, so you can execute your application.
configurations {
providedCompile
}
dependencies {
compile "define your dependencies that should be added to the zipfile"
providedCompile "dependencies that shouldnt be added to the zipfile"
}
compileJava {
sourceSets.main.compileClasspath += configurations.providedCompile
}
run {
classpath += configurations.providedCompile
}
This script ensures, that you have all librarys on your classpath that are required to run your script and it excludes all librarys defined in "providedCompile" from the distZip scope. Feel free to change the name of the configuration called providedCompile.
Alternativly, you can create your own distTask: Provide own script when using plugin application in Gradle 1.0
Try this by adding below lines in build.gradle file:
distributions {
main {
baseName = 'ClassName'
contents {
exclude("**/*.jar")
}
}
}
The application plugin provides a configuration element applicationDistribution
, which allows you to exclude specific things from the distribution targets, e.g.:
applicationDistribution.exclude('foo*.jar')
or if you'd like to exclude several things, you can use a Groovy with
block:
applicationDistribution.with {
exclude 'foo*.jar'
exclude 'bar*.jar'
}