(Gradle) Shadow Jar problems

Discussion in 'Spigot Plugin Development' started by jusjus112, Jun 12, 2018.

  1. Hey colleagues,

    Recently I am working on a new project and started using "Hakari"
    Because I'm using some external libraries and those are not actual plugins I have to use
    shadow jar in order to compile it with my jar.

    The problem now is that it is compiling it into my jar, but Hikari is giving error and it is compiling all the sources there are. My compiled jar is containing:

    [​IMG]

    This is my build.gradle:

    Code (Java):
    buildscript {
        repositories {
            jcenter()
            maven {
                url "https://plugins.gradle.org/m2/"
            }
        }
        dependencies {classpath "com.github.jengelman.gradle.plugins:shadow:2.0.4"}
    }

    plugins {
        id 'com.github.johnrengelman.shadow' version '2.0.4'
        id 'java'
        id 'maven'
        id 'eclipse'
        id 'application'
    }

    compileJava.options.encoding = 'UTF-8'
    group 'backend-synergy'
    mainClassName = 'usa.devrocoding.backend.Backend'
    version '1.0-SNAPSHOT'
    sourceCompatibility = 1.8
    defaultTasks 'clean', 'build'

    jar.enabled = true
    tasks.jar.enabled = true

    repositories {
        mavenCentral()
        mavenLocal()
        jcenter()

        flatDir {
            dirs 'libs'
        }

        maven {
            url "http://repo.dmulloy2.net/content/groups/public/"
        }

        maven {
            url = 'https://oss.sonatype.org/content/repositories/snapshots'
        }

        maven {
            url "https://mvnrepository.com/artifact/redis.clients/jedis"
        }
    }

    configurations {
        provided
        compile.extendsFrom provided
    }

    shadowJar {
        baseName = 'Backend'
        classifier = null
        version = '1.0.0'

        mergeServiceFiles()
        dependencies {
            include(dependency('org.slf4j:.*'))
            include(dependency('redis.clients:.*'))
            include(dependency('org.apache.commons:.*'))
            include(dependency('com.google.code.gson:.*'))
            include(dependency('com.zaxxer:.*'))
            include(dependency('jline:.*'))
        }
    }

    dependencies {
        testCompile group: 'junit', name: 'junit', version: '4.12'

        compile fileTree(dir: 'libs', include: '*.jar')

        compileOnly "org.projectlombok:lombok:1.16.16"

        compile group: 'redis.clients', name: 'jedis', version: '2.9.0'
        compile group: 'com.google.code.gson', name: 'gson', version: '2.3.1'
        compile group: 'com.google.guava', name: 'guava', version: 'r05'
        compile "com.zaxxer:HikariCP:2.7.8"
    }

    processResources {
        expand project.properties
    }
    Hope anyone can help me because I don't understand this.
     
  2. The actual error would help
     
  3. Code (Text):
     SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
    SLF4J: Defaulting to no-operation (NOP) logger implementation
    SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
    java.lang.NullPointerException
         at java.util.Hashtable.put(Unknown Source)
         at com.zaxxer.hikari.HikariConfig.addDataSourceProperty(HikariConfig.java:453)
         at usa.devrocoding.synergy.services.sql.DatabaseManager.connect(DatabaseManager.java:34)
         at usa.devrocoding.synergy.services.SQLService.<init>(SQLService.java:23)
         at usa.devrocoding.synergy.spigot.Core.onEnable(Core.java:58)
         at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264)
         at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337)
         at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:402)
         at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugin(CraftServer.java:374)
         at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugins(CraftServer.java:323)
         at net.minecraft.server.v1_12_R1.MinecraftServer.t(MinecraftServer.java:421)
         at net.minecraft.server.v1_12_R1.MinecraftServer.l(MinecraftServer.java:382)
         at net.minecraft.server.v1_12_R1.MinecraftServer.a(MinecraftServer.java:337)
         at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:272)
         at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:544)
         at java.lang.Thread.run(Unknown Source)
    This is the error.. But also one of the problems are that shadow jar is compiling all the libs. I just got 6 libs I want to load, not all those other stuff.
     
  4. Looks like an issue with your actual code rather than a shading issue. Provide the class mentioned in the stack trace.