Wolfizen

Gradle Shadow Plugin

Jun 15th, 2016
821
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 1.38 KB | None | 0 0
  1. // Required code is commented with // REQ
  2. // Better than some other solutions because dependencies don't need to be declared twice
  3. // As in, "shadow 'my-dep:0.1'" also adds it to the compile dependencies list
  4.  
  5. plugins {
  6.     id 'java'
  7.     id 'idea'
  8.     id 'com.github.johnrengelman.shadow' version '1.2.3' // REQ
  9. }
  10.  
  11. group '...'
  12. version '1.0-SNAPSHOT'
  13.  
  14. // Dependencies
  15.  
  16. repositories {
  17.     mavenCentral()
  18.     maven {
  19.         name = 'sponge'
  20.         url = 'http://repo.spongepowered.org/maven'
  21.     }
  22. }
  23.  
  24. dependencies {
  25.     compile 'org.spongepowered:spongeapi:4.1.0-SNAPSHOT'
  26.     shadow 'org.mongodb:mongodb-driver:3.2.2' // REQ (replace with your desired dependency)
  27.     shadow 'org.jgrapht:jgrapht-core:0.9.1'
  28.     shadow 'org.reflections:reflections:0.9.10'
  29.     testCompile group: 'junit', name: 'junit', version: '4.11'
  30. }
  31.  
  32. idea {
  33.     module {
  34.         downloadJavadoc = true
  35.         downloadSources = true
  36.     }
  37. }
  38.  
  39. // Build
  40.  
  41. project.configurations.compile.extendsFrom(project.configurations.shadow) // REQ
  42.  
  43. // BEGIN REQ
  44. shadowJar {
  45.     classifier = 'dist' // (this will be appended to the jar filename. Ex: myProj-dist.jar)
  46.     configurations = [project.configurations.shadow]
  47.     dependencies {
  48.         exclude(dependency('com.google.guava:guava')) // (replace with any child dependencies that you don't want)
  49.     }
  50. }
  51.  
  52. build.dependsOn(shadowJar)
  53. // END REQ
Advertisement