1buildscript { 2 dependencies { 3 classpath 'com.google.guava:guava:30.0-android' 4 } 5} 6 7plugins { 8 id "java-library" 9 id "java-test-fixtures" 10 id "maven-publish" 11 12 id "me.champeau.gradle.japicmp" 13 id "me.champeau.jmh" 14 id "ru.vyarus.animalsniffer" 15} 16 17import static java.nio.charset.StandardCharsets.US_ASCII; 18 19import com.google.common.primitives.Bytes; 20 21description = 'gRPC: Core' 22 23dependencies { 24 api project(':grpc-api') 25 implementation libraries.gson, 26 libraries.android.annotations, 27 libraries.animalsniffer.annotations, 28 libraries.errorprone.annotations, 29 libraries.guava, 30 libraries.perfmark.api 31 testFixturesApi libraries.junit 32 testFixturesImplementation libraries.guava, 33 libraries.mockito.core, 34 libraries.truth, 35 project(':grpc-testing') 36 testImplementation testFixtures(project(':grpc-context')), 37 testFixtures(project(':grpc-api')), 38 project(':grpc-testing'), 39 project(':grpc-grpclb') 40 testImplementation (libraries.guava.testlib) { 41 exclude group: 'junit', module: 'junit' 42 } 43 44 testRuntimeOnly project(':grpc-census') 45 46 jmh project(':grpc-testing') 47 48 signature libraries.signature.java 49 signature libraries.signature.android 50} 51 52tasks.named("javadoc").configure { 53 exclude 'io/grpc/internal/**' 54 exclude 'io/grpc/inprocess/Internal*' 55 // Disabled until kinda stable. 56 exclude 'io/grpc/perfmark/**' 57} 58 59animalsniffer { 60 // Don't check sourceSets.jmh 61 sourceSets = [ 62 sourceSets.main, 63 sourceSets.test 64 ] 65} 66 67components.java.withVariantsFromConfiguration(configurations.testFixturesApiElements) { skip() } 68components.java.withVariantsFromConfiguration(configurations.testFixturesRuntimeElements) { skip() } 69 70import net.ltgt.gradle.errorprone.CheckSeverity 71 72def replaceBytes(byte[] haystack, byte[] needle, byte[] replacement) { 73 int i = Bytes.indexOf(haystack, needle); 74 assert i != -1; 75 byte[] result = new byte[haystack.length - needle.length + replacement.length]; 76 System.arraycopy(haystack, 0, result, 0, i); 77 System.arraycopy(replacement, 0, result, i, replacement.length); 78 System.arraycopy(haystack, i + needle.length, result, i + replacement.length, haystack.length - i - needle.length); 79 return result; 80} 81 82def bigEndianShortBytes(int value) { 83 return [value >> 8, value & 0xFF] as byte[]; 84} 85 86def replaceConstant(File file, String needle, String replacement) { 87 // CONSTANT_Utf8_info. https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.4.7 88 byte[] needleBytes = Bytes.concat( 89 [1] as byte[], bigEndianShortBytes(needle.length()), needle.getBytes(US_ASCII)); 90 byte[] replacementBytes = Bytes.concat( 91 [1] as byte[], bigEndianShortBytes(replacement.length()), replacement.getBytes(US_ASCII)); 92 file.setBytes(replaceBytes(file.getBytes(), needleBytes, replacementBytes)); 93} 94 95plugins.withId("java") { 96 tasks.named("compileJava").configure { 97 doLast { 98 // Replace value of Signature Attribute. 99 // https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.7.9 100 // 101 // Have new compilations compile against a public class, without breaking the internal 102 // ABI for the moment. After giving users some time to recompile, this should be removed 103 // and #7211 can continue. When this is removed, at the very least the generics need to 104 // be changed to avoid <? extends io.grpc.internal.*>. 105 project.replaceConstant( 106 destinationDirectory.file( 107 "io/grpc/internal/AbstractManagedChannelImplBuilder.class").get().getAsFile(), 108 "<T:Lio/grpc/internal/AbstractManagedChannelImplBuilder<TT;>;>Lio/grpc/ManagedChannelBuilder<TT;>;", 109 "<T:Lio/grpc/ManagedChannelBuilder<TT;>;>Lio/grpc/ManagedChannelBuilder<TT;>;"); 110 project.replaceConstant( 111 destinationDirectory.file( 112 "io/grpc/internal/AbstractServerImplBuilder.class").get().getAsFile(), 113 "<T:Lio/grpc/internal/AbstractServerImplBuilder<TT;>;>Lio/grpc/ServerBuilder<TT;>;", 114 "<T:Lio/grpc/ServerBuilder<TT;>;>Lio/grpc/ServerBuilder<TT;>;"); 115 } 116 } 117} 118 119tasks.register("versionFile") { 120 doLast { 121 new File(buildDir, "version").write("${project.version}\n") 122 } 123} 124