[JAVA] Make fat Jar with Minecraft modding

What is fatJar in the first place?

When using a third-party library etc., including that library, everything is in one jar file (I think).

This environment

The first one ・ IntelliJ IDEA Community Edition 2016.3.4 ・ Forge 1.7.10-10.13.4.1614 ・ Forge Gradle 1.2

Second ・ IntelliJ IDEA Community Edition 2016.3.4 ・ Forge 1.11.2-13.20.1.2386 ・ Forge Gradle 2.2-SNAPSHOT

how can I do?

  1. Open build.gradle
  2. Add the following source (if minecraft {} etc. already exists, add it there)
  3. After executing the build task, fatJar is completed!

** * Please do not write <>. Also, please keep the order of minecraft, configurations, dependencies, jar as it is. In the code below, delete between "from here" and "up to here" in the 1.11.2 environment. ** **

//from here
minecraft {
    srgExtra "PK: <The root directory of that library> <Path when making a jar file>"
}
//So far

configurations{
    shade
    compile.extendsFrom shade
}

dependencies {
    <Change compile to shade, see below for details>
}

jar {
    configurations.shade.each {dep ->
        from(project.zipTree(dep)){
            exclude 'META-INF', 'META-INF/**'
        }
    }
}

Usage example (only necessary parts)

//from here
minecraft {
    srgExtra "PK: com/fasterxml/jackson/annotation com/fasterxml/jackson/annotation"
    srgExtra "PK: com/fasterxml/jackson/core com/fasterxml/jackson/core"
    srgExtra "PK: com/fasterxml/jackson/databind com/fasterxml/jackson/databind"
}
//So far

configurations{
    shade
    compile.extendsFrom shade
}

dependencies {
    shade group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.0'
}

jar {
    configurations.shade.each {dep ->
        from(project.zipTree(dep)){
            exclude 'META-INF', 'META-INF/**'
        }
    }
}

Recommended Posts

Make fat Jar with Minecraft modding
Minecraft Modding 1.12.2
Gradle + Kotlin-Generate jar with DSL
Microservices with DevOps Make Changes
How to make a jar file with no dependencies in Maven
Try to make a cross-platform application with JRuby (jar file generation)