Skip to content

Instantly share code, notes, and snippets.

@martinandersson
Created March 3, 2015 05:57
Show Gist options
  • Save martinandersson/c63675ce87947da1ef4a to your computer and use it in GitHub Desktop.
Save martinandersson/c63675ce87947da1ef4a to your computer and use it in GitHub Desktop.
apply plugin: 'java'
apply plugin: 'java-library-distribution'
repositories {
mavenCentral()
}
dependencies {
compile 'org.apache.commons:commons-lang3:3.3.2'
}
// Task "distZip" added by plugin "java-library-distribution":
distZip.shouldRunAfter(build)
jar {
// Keep jar clean:
exclude 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA', 'META-INF/*.MF'
manifest {
attributes 'Main-Class': 'com.somepackage.MainClass',
'Class-Path': configurations.runtime.files.collect { "lib/$it.name" }.join(' ')
}
// How-to add class path:
// http://stackoverflow.com/questions/22659463/add-classpath-in-manifest-using-gradle
// https://gist.github.com/simon04/6865179
}
@martinandersson
Copy link
Author

A textual preview of the results can be found here.

@NielsUll
Copy link

NielsUll commented Aug 26, 2016

If you use gradle 3.0 and the io.spring.gradle:dependency-management-plugin, you must delay setting the Class-Path like this:

afterEvaluate {
     jar {
        manifest {
            attributes (
                    'Class-Path': configurations.runtime.files.collect { "lib/$it.name" }.join(' ')
            )
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment