1buildscript {
2    repositories { jcenter() }
3    dependencies { classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4' }
4}
5
6apply plugin: 'com.github.johnrengelman.shadow'
7
8description = "gRPC: Netty Shaded"
9
10sourceSets { testShadow {} }
11
12dependencies {
13    compile project(':grpc-netty')
14    runtime libraries.netty_tcnative
15    testShadowCompile files(shadowJar),
16            configurations.shadow,
17            project(':grpc-testing-proto'),
18            project(':grpc-testing'),
19            libraries.truth
20    shadow project(':grpc-core')
21}
22
23artifacts { // We want uploadArchives to handle the shadowJar; we don't care about
24    // uploadShadow
25    archives shadowJar }
26
27jar {
28    // Must use a different classifier to avoid conflicting with shadowJar
29    classifier = 'original'
30}
31configurations.archives.artifacts.removeAll { it.classifier == "original" }
32
33shadowJar {
34    classifier = null
35    dependencies {
36        include(project(':grpc-netty'))
37        include(dependency('io.netty:'))
38    }
39    relocate 'io.grpc.netty', 'io.grpc.netty.shaded.io.grpc.netty'
40    relocate 'io.netty', 'io.grpc.netty.shaded.io.netty'
41    // We have to be careful with these replacements as they must not match any
42    // string in NativeLibraryLoader, else they cause corruption. Note that
43    // this includes concatenation of string literals and constants.
44    relocate 'META-INF/native/libnetty', 'META-INF/native/libio_grpc_netty_shaded_netty'
45    relocate 'META-INF/native/netty', 'META-INF/native/io_grpc_netty_shaded_netty'
46    mergeServiceFiles()
47}
48
49// This is a hack to have shadow plugin modify the uploadArchives POM's
50// dependencies. If we delete the uploadShadow task, then the plugin will no
51// longer modify the POM. This probably can break horribly with parallel build,
52// but that's broken anyway with install/uploadArchives
53uploadShadow.repositories.addAll(uploadArchives.repositories)
54// And then we use a further hack to share that POM with install
55install.repositories.mavenInstaller.pom = uploadArchives.repositories.mavenDeployer.pom
56
57task testShadow(type: Test) {
58    testClassesDirs = sourceSets.testShadow.output.classesDirs
59    classpath = sourceSets.testShadow.runtimeClasspath
60}
61compileTestShadowJava.options.compilerArgs = compileTestJava.options.compilerArgs
62compileTestShadowJava.options.encoding = compileTestJava.options.encoding
63
64test.dependsOn testShadow
65