Have shadowJar do its thing on a jar another gradle plugin has produced

A bit of background info.

Minecraft forge is a modding api for Minecraft. It obfuscates the code via a gradle plugin so the modded code can work with minecraft.

Now, I want to use gradle shadowjar to add sqlite jar into the obfuscated jar the forge gradle plugin produces.

What i’m running into is that shadowJar creates its own jar with the deobfuscated code, which will not work with minecraft because it does not know the deobfuscated fields.

How can I get shadowJar to do its magic on the obfuscated jar the forge gradle plugin produces?

buildscript {
    repositories {
        maven {
            name = "forge"
            url = "http://files.minecraftforge.net/maven"
        maven {
            name = "sonatype"
            url = "https://oss.sonatype.org/content/repositories/snapshots/"
        maven {
            name = "shadow"
            url "https://plugins.gradle.org/m2/"
    dependencies {
        classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT'
        classpath "com.github.jengelman.gradle.plugins:shadow:1.2.1"
apply plugin: 'java' // or 'groovy'. Must be explicitly applied
apply plugin: 'com.github.johnrengelman.shadow'
shadowJar {
    relocate 'org.sqlite','something.something.org.sqlite'

apply plugin: 'forge'

version = ""
group= "something.something.modname" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "modname"

minecraft {
    version = "1.8-"
    runDir = "eclipse"

    // the mappings can be changed at any time, and must be in the following format.
    // snapshot_YYYYMMDD   snapshot are built nightly.
    // stable_#            stables are built at the discretion of the MCP team.
    // Use non-default mappings at your own risk. they may not allways work.
    // simply re-run your setup task after changing the mappings to update your workspace.
    mappings = "snapshot_20141130"

    // this will ensure that this task is redone when the versions change.
    inputs.property "version", project.version
    inputs.property "mcversion", project.minecraft.version

    // replace stuff in mcmod.info, nothing else
    from(sourceSets.main.resources.srcDirs) {
        include 'mcmod.info'

        // replace version and mcversion
        expand 'version':project.version, 'mcversion':project.minecraft.version

    // copy everything else, thats not the mcmod.info
    from(sourceSets.main.resources.srcDirs) {
        exclude 'mcmod.info'
// Include external libs in compilation and jar
configurations {
    compile.extendsFrom external
dependencies {
    // you may put jars on which you depend on in ./libs
    // or you may define them like so..
    //compile "some.group:artifact:version:classifier"
    //compile "some.group:artifact:version"

    // real examples
    //compile 'com.mod-buildcraft:buildcraft:6.0.8:dev'  // adds buildcraft to the dev env
    //compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env

    // for more info...
    // http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
    // http://www.gradle.org/docs/current/userguide/dependency_management.html


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

// Let Shadow do its thing
build.dependsOn shadowJar

And the modfile i’m experimenting with

package something.something;

import net.minecraft.init.Blocks;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import java.sql.*;

@Mod(modid = modname.MODID, version = modname.VERSION)
public class modname
    // set this to true when compiling for production
    private boolean goingLive = true;
    public static final String MODID = "modname";
    public static final String VERSION = "";

    public void init(FMLInitializationEvent event)
        // This causes the crash in a real minecraft enviroment because it's not obfuscated
        System.out.println("DIRT BLOCK >> "+Blocks.dirt.getUnlocalizedName());

            Connection c = null;
            try {
              c = DriverManager.getConnection("jdbc:sqlite:test.db");
            } catch ( Exception e ) {
              System.err.println( e.getClass().getName() + ": " + e.getMessage() );
            System.out.println("Opened database successfully");


I’m not familiar with the minecraft forge plugin but I assume that somehow the final jar produced by the ‘jar’ task contains the “obfuscated” code. In that case, I suppose you could tell the shadowJar task to include the contents of that jar, rather than the default output of the javaCompile task.

shadowJar {
    from zipTree(jar.archivePath)
configurations {
    compile.extendsFrom provided

dependencies {
    provided 'WHATEVER' // Packages you don't need to add to jar
    provided 'Other WHATEVER' // Packages you don't need to add to jar

    shadow 'OTHER' // Packages you need to add to jar
    shadow 'Another OTHER' // Packages you need to add to jar

shadowJar {
    configurations = [project.configurations.shadow] // ***

as mentioned here

line *** is the way to tell shadow what dependencies to include in jar