0

Yo folks basically I'm using gradle in java project and can't export the libraries in jar file that I'm using. Tried a few solutions but nothing worked. Do you know what I'm missing in the gradle file or I need to specify some things when I'm exporting. I'm using Eclipse

Thanks, here is my gradle file

    enter code here
plugins {
    // Apply the java-library plugin to add support for Java Library
    id 'java-library'

}

repositories {
    // Use jcenter for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
    mavenCentral()
}

dependencies {
    // This dependency is exported to consumers, that is to say found on their compile classpath.
    api 'org.apache.commons:commons-math3:3.6.1'

    // This dependency is used internally, and not exposed to consumers on their own compile classpath.
    implementation 'com.google.guava:guava:27.0.1-jre'

    // Use JUnit test framework
    testImplementation 'junit:junit:4.12'

    implementation "redis.clients:jedis:3.0.1"
    implementation  'org.pixsee.java-fcm:Java-fcm:1.0.0'  

    implementation 'com.google.firebase:firebase-admin:6.10.0'


    compile "org.slf4j:slf4j-api:1.6.1"

     implementation 'org.slf4j:slf4j-simple:1.7.25'
     implementation "com.google.maps:google-maps-services:0.9.4"
     implementation 'io.vertx:vertx-core:3.8.1'

}
sourceCompatibility = 1.8
version = '1.0'
jar {
    manifest {
        attributes 'Implementation-Title': 'GeofenceServer',
                   'Implementation-Version': version
    }
}
apply plugin: "eclipse"
Markku K.
  • 3,840
  • 19
  • 20
  • It seems you're missing the entire gradle file. – Kayaman Sep 13 '19 at 11:20
  • in other words, we cannot know what is missing since you have not posted anything – user85421 Sep 13 '19 at 11:25
  • sorry just saw It ,basically now I reading I have to create a fat jar file . –  Sep 13 '19 at 12:11
  • 1
    try [this](https://www.mkyong.com/gradle/gradle-create-a-jar-file-with-dependencies/) – Sterconium Sep 13 '19 at 15:46
  • what solutions did you try? there are a number of ways to build a "fat jar", that is, a jar containing your code + all dependencies. Have you tried > this? https://stackoverflow.com/questions/4871656/using-gradle-to-build-a-jar-with-dependencies – Daniele Sep 14 '19 at 14:59

1 Answers1

0

Finally solved it , the answer from Sterconium got me on the right track answer but the problem was when I try to create the fatJar it says cannot find the main class ,the reason was because my files are in src/test/java instead of src/main/java and somehow when I tried to run fatJar it compiled It but could not find still the dependencies, so I change the implementation to compile in build.gradle file and now it works .So here is my final build.gradle file how it looks like .

    /*
 * This file was generated by the Gradle 'init' task.
 *
 * This generated file contains a sample Java Library project to get you started.
 * For more details take a look at the Java Libraries chapter in the Gradle
 * User Manual available at https://docs.gradle.org/5.4/userguide/java_library_plugin.html
 */
plugins {
    // Apply the java-library plugin to add support for Java Library
    id 'java-library'
}
repositories {
    // Use jcenter for resolving your dependencies.
    // You can declare any Maven/Ivy/file repository here.
    jcenter()
    mavenCentral()
}


apply plugin: "java"
apply plugin: "eclipse"

version = '1.0'

//create a single Jar with all dependencies
task fatJar(type: Jar) {
    manifest {
        attributes 'Implementation-Title': 'Gradle Jar File Example', 
            'Implementation-Version': version,
            'Main-Class': 'Server.Test'
    }
    baseName = project.name + '-all'
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
}


dependencies {
    // This dependency is exported to consumers, that is to say found on their compile classpath.
    api 'org.apache.commons:commons-math3:3.6.1'


    // This dependency is used internally, and not exposed to consumers on their own compile classpath.
    implementation 'com.google.guava:guava:27.0.1-jre'

    // Use JUnit test framework
    testImplementation 'junit:junit:4.12'


    implementation "redis.clients:jedis:3.0.1"
    implementation 'com.google.firebase:firebase-admin:6.10.0'
    implementation 'org.slf4j:slf4j-simple:1.7.25'
    implementation 'com.google.maps:google-maps-services:0.10.0'
    compile 'io.vertx:vertx-core:3.8.1'
    implementation 'com.google.code.gson:gson:2.8.5'
}