I use Eclipse IDE in conjunction with Gradle. I stumbled over a problem with the packaging in the Runnable Jar of the library connected to the project — it does not appear in the jar. To get it, use the 'build' command.

When a Runnable Jar is received via the standard environment tools (Ant), all classes from the library appear in the 'com' folder and the jar is launched. But besides them, there is a lot of excess garbage, which does not affect anything, but it weighs a lot. Yes, and I do not want to throw Gradle. Through Gradle, neither classes nor, accordingly, the starting jar fails.

My build.gradle

apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'application' mainClassName = 'formatter.MainView' jar { baseName = 'PostMaker ' version = ' v2.0 Alpha' manifest.attributes("Main-Class": mainClassName); manifest.attributes("Class-Path": '.'); } repositories { mavenCentral() } dependencies { compile group: 'commons-collections', name: 'commons-collections', version: '3.2' compile 'com.mpatric:mp3agic:0.8.4' testCompile group: 'junit', name: 'junit', version: '4.+' } test { systemProperties 'property': 'value' } uploadArchives { repositories { flatDir { dirs 'repos' } } } task wrapper(type: Wrapper) { gradleVersion = '2.10' } 

    2 answers 2

    I found a solution (although the classes are unpacked into a folder, I wanted it in jar archives, not critical):

     jar { baseName = 'name' version = 'version' // Keep jar clean: exclude 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA', 'META-INF/*.MF' manifest { attributes 'Main-Class': mainClassName, //Заполняем classpath в манифесте 'Class-Path': configurations.runtime.files.collect { "$it.name" }.join(' ') } //Добавление class-файлов библиотек в runnable jar from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } configurations.runtime.collect { it.isDirectory() ? it : zipTree(it) } } } 

      You can also use plugins: shadow , gradle-one-jar , gradle-capsule-plugin

      Took from here and from here .

      And what you do, try to do with a smaller code like this:

       jar { ... from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } ... } 

      True, in the comments I write that there may be problems if there are too many files.