As others noted, in order for the jar file to be executable, the entry point of the application must be set in the Main-Class attribute of the manifest file. If dependency class files are not placed together, they must be specified in the Class-Path entry of the manifest file.
I tried all kinds of combinations of plugins and thatβs not for the simple task of creating an executable jar and anyway, including dependencies. It seems that all the plugins are somehow lacking, but finally I got it the way I wanted. No cryptic scripts, not a million different mini files that pollute the build directory, a pretty clean build script file, and most importantly: not a million third-party class files merged into my jar archive.
The following is a copy-paste from here for your convenience ..
[How-to] create a distribution zip file with jar dependencies in the /lib subdirectory and add all the dependencies to the Class-Path entry in the manifest file:
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: // https://stackoverflow.com/questions/22659463/add-classpath-in-manifest-using-gradle // https://gist.github.com/simon04/6865179 }
Hosting is the essence here .
The result can be found in build/distributions and the unzipped content is as follows:
Lib / Common-lang3-3.3.2.jar
MyJarFile.jar
The content of MyJarFile.jar#META-INF/MANIFEST.mf :
Manifest Version: 1.0
Main class: com.somepackage.MainClass
Class Path: lib / commons-lang3-3.3.2.jar
Martin Andersson Mar 03 '15 at 6:23 2015-03-03 06:23
source share