简体   繁体   中英

Shade/shadow in local jar to gradle project

I'm new to gradle and attempting to compile my project, but also "shade in" (as you would in maven) a local jar file.

I'm attempting to use the gradle shadow plugin, however when I run "shadowJar" it doesn't create a jar file with the dependency I wish to shade/shadow in.

How can I properly shade in the contents of a local jar dependency using gradle? Just need someone to point me in the proper direction as I can't find anything about it. Thanks!

Here is my build.gradle:

group 'org.primemc'
version '1.0-SNAPSHOT'

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.3'
    }
}

apply plugin: 'java'
apply plugin: 'com.github.johnrengelman.shadow'

sourceCompatibility = 1.8

repositories {
    mavenCentral()

    maven {
        name 'Spigot'
        url 'https://hub.spigotmc.org/nexus/content/groups/public/'
    }

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

    maven {
        url 'https://nexus.solucorpus.com/repository/maven-all/'
    }
}

dependencies {
    compile 'org.spigotmc:spigot-api:1.8.8-R0.1-SNAPSHOT'    
    compileOnly "org.projectlombok:lombok:1.16.12"

    compile files('./lib/redemptive-core-1.1-SNAPSHOT.jar')
    compile files('./lib/craftbukkit-1.8.8.jar')
    compile 'io.reactivex:rxjava:1.1.6'    

    // Not sure if this is correct or not.. doesn't seem to work.
    shadow files('./lib/redemptive-core-1.1-SNAPSHOT.jar')
}

shadowJar {
    dependencies {
        //Attempting to shade/shadow this jar into the one built.
        include('./lib/redemptive-core-1.1-SNAPSHOT.jar')
    }
}

This worked for me:

shade fileTree(dir: 'lib', include: '<filename>.jar')

Using file() didn't work for me, not sure whether that's due to incorrect syntax, but fileTree did the trick, and also allows for wildcards.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM