java – Gradle does not collect Runnable Jar


Recently I moved to Eclipse from regular build tools to Gradle, I was tormented with tasks and the very last one puzzled me. I need to build a Runnable Jar file and I use the "jar" task (only this if important). As a result, a cut is issued in the form of 27 kb, where there are not enough internals, and it does not start. Previously, the launching jar weighed 200-300 kb.


apply plugin: 'java'  
apply plugin: 'eclipse'
apply plugin: 'application'

mainClassName = 'formatter.FormatterMain'
jar {
    baseName = 'PostMaker'
    version =  '2.0_Alpha'

repositories {

dependencies {
    compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
    testCompile group: 'junit', name: 'junit', version: '4.+'

test {
    systemProperties 'property': 'value'

uploadArchives {
    repositories {
       flatDir {
           dirs 'repos'

PS: I also need help in connecting third-party libraries in the form of jar files, perhaps the problem is because of them, I can't find them in the jar file. Although Eclipse ran fine without them.


Turned out to be much easier than I thought:

manifest.attributes("Main-Class": mainClassName);

This line, added to the jar block in the build.gradle file, solved the issue with the executable jar file.

mainClassName is a variable with the main class.

Scroll to Top