gradlejenashadowjar

Gradle with Apache Jena 3.11.0


I am trying to create a shadowjar including the latest Apache Jena 3.11 using the gradle build system and additional java code to create an "uber" package. To do so I found information here: https://jena.apache.org/documentation/notes/jena-repack.html however I am having difficulty to translate this to a gradle setup.

Does anyone knows how to achieve this?

5 actionable tasks: 1 executed, 4 up-to-date
Creating memory store
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.
Exception in thread "main" java.lang.ExceptionInInitializerError
    at nl.wur.ssb.RDFSimpleCon.RDFSimpleCon.createEmptyStore(RDFSimpleCon.java:150)
    at nl.wur.ssb.RDFSimpleCon.RDFSimpleCon.<init>(RDFSimpleCon.java:62)
    at nl.wur.ssb.RDFSimpleCon.RDFSimpleCon.<init>(RDFSimpleCon.java:159)
    at nl.wur.ssb.RDFSimpleCon.Test.main(Test.java:7)
Caused by: java.lang.NullPointerException
    at org.apache.jena.tdb.sys.EnvTDB.processGlobalSystemProperties(EnvTDB.java:33)
    at org.apache.jena.tdb.TDB.init(TDB.java:252)
    at org.apache.jena.tdb.sys.InitTDB.start(InitTDB.java:29)
    at org.apache.jena.sys.JenaSystem.lambda$init$2(JenaSystem.java:116)
    at java.util.ArrayList.forEach(ArrayList.java:1257)
    at org.apache.jena.sys.JenaSystem.forEach(JenaSystem.java:191)
    at org.apache.jena.sys.JenaSystem.forEach(JenaSystem.java:168)
    at org.apache.jena.sys.JenaSystem.init(JenaSystem.java:114)
    at org.apache.jena.tdb.TDBFactory.<clinit>(TDBFactory.java:40)
    ... 4 more

Solution

  • Java ServiceLoader files need to be merged when creating a repackaged jar file.

    For Gradle, this is done with "mergeServiceFiles()" when using the shadowJar.

    https://jena.apache.org/documentation/notes/jena-repack.html has the instructions for the Maven shade plugin.