Skip to content

Commit 204ec05

Browse files
authored
Update R8 and Gr8 (#6280)
1 parent 8a78bd0 commit 204ec05

File tree

8 files changed

+286
-310
lines changed

8 files changed

+286
-310
lines changed

gradle/libraries.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ dgp = "com.gradle:develocity-gradle-plugin:3.18.2" # // sync with settings.gradl
9898
# annotation @org.jetbrains.annotations.Nullable not applicable in this type context
9999
google-testing-compile = { group = "com.google.testing.compile", name = "compile-testing", version = "0.19" }
100100
google-testparameterinjector = { group = "com.google.testparameterinjector", name = "test-parameter-injector", version = "1.11" }
101-
gr8 = { group = "com.gradleup", name = "gr8-plugin", version = "0.8" }
101+
gr8 = { group = "com.gradleup", name = "gr8-plugin", version = "0.11.1" }
102102
#
103103
# See https://github.com/gradle/gradle/issues/1835
104104
# We use the Nokee[redistributed artifacts](https://docs.nokee.dev/manual/gradle-plugin-development.html#sec:gradle-dev-redistributed-gradle-api)

gradle/repositories.gradle.kts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,24 @@ listOf(pluginManagement.repositories, dependencyResolutionManagement.repositorie
77
exclusiveContent {
88
forRepository(::google)
99
filter {
10-
includeModuleByRegex("com\\.android.*", ".*")
10+
includeGroup("com.android")
11+
includeGroup("com.android.library")
12+
includeGroup("com.android.application")
13+
includeGroup("com.android.databinding")
14+
includeGroup("com.android.lint")
15+
includeGroup("com.google.testing.platform")
16+
/*
17+
* The com.android.tools groupId is verbose because we don't want to clash with com.android.tools:r8 in the raw repository
18+
*/
19+
includeModule("com.android.tools", "sdk-common")
20+
includeModule("com.android.tools", "sdklib")
21+
includeModule("com.android.tools", "repository")
22+
includeModule("com.android.tools", "common")
23+
includeModule("com.android.tools", "dvlib")
24+
includeModule("com.android.tools", "annotations")
25+
includeModule("com.android.tools", "play-sdk-proto")
26+
includeGroupByRegex("com\\.android\\.tools\\..*")
1127
includeModuleByRegex("androidx\\..*", ".*")
12-
includeModuleByRegex("com.google.testing.platform", ".*")
1328
}
1429
}
1530

libraries/apollo-ast/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88
}
99

1010
apolloLibrary(
11-
namespace = "com.apollographql.apollo.ast"
11+
namespace = "com.apollographql.apollo.ast",
1212
)
1313

1414
kotlin {

libraries/apollo-compiler/api/apollo-compiler.api

Lines changed: 225 additions & 225 deletions
Large diffs are not rendered by default.

libraries/apollo-compiler/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
12
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
23

34
plugins {
@@ -6,7 +7,8 @@ plugins {
67
}
78

89
apolloLibrary(
9-
namespace = "com.apollographql.apollo.compiler"
10+
namespace = "com.apollographql.apollo.compiler",
11+
kotlinCompilerOptions = KotlinCompilerOptions(KotlinVersion.KOTLIN_1_9)
1012
)
1113

1214
dependencies {

libraries/apollo-gradle-plugin-external/build.gradle.kts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
2+
13
plugins {
24
id("org.jetbrains.kotlin.jvm")
35
id("java-gradle-plugin")
@@ -8,7 +10,8 @@ plugins {
810

911
apolloLibrary(
1012
namespace = "com.apollographql.apollo.gradle",
11-
jvmTarget = 11 // AGP requires 11
13+
jvmTarget = 11, // AGP requires 11
14+
kotlinCompilerOptions = KotlinCompilerOptions(KotlinVersion.KOTLIN_1_9)
1215
)
1316

1417
dependencies {

libraries/apollo-gradle-plugin/build.gradle.kts

Lines changed: 20 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,26 @@
1+
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
2+
13
plugins {
24
id("org.jetbrains.kotlin.jvm")
35
id("java-gradle-plugin")
46
id("com.gradle.plugin-publish")
57
id("com.gradleup.gr8")
68
}
79

10+
val jvmTarget = 11 // AGP requires 11
811
apolloLibrary(
912
namespace = "com.apollographql.apollo.gradle.relocated",
10-
jvmTarget = 11 // AGP requires 11
13+
jvmTarget = jvmTarget,
14+
kotlinCompilerOptions = KotlinCompilerOptions(KotlinVersion.KOTLIN_1_9)
1115
)
1216

13-
// Configuration for extra jar to pass to R8 to give it more context about what can be relocated
14-
configurations.create("gr8Classpath")
15-
// Configuration dependencies that will be shadowed
16-
val shadeConfiguration = configurations.create("shade")
17-
1817
// Set to false to skip relocation and save some building time during development
1918
val relocateJar = System.getenv("APOLLO_RELOCATE_JAR")?.toBoolean() ?: true
2019

21-
dependencies {
22-
/**
23-
* OkHttp has some bytecode that checks for Conscrypt at runtime (https://github.com/square/okhttp/blob/71427d373bfd449f80178792fe231f60e4c972db/okhttp/src/main/kotlin/okhttp3/internal/platform/ConscryptPlatform.kt#L59)
24-
* Put this in the classpath so that R8 knows it can relocate DisabledHostnameVerifier as the superclass is not package-private
25-
*
26-
* Keep in sync with https://github.com/square/okhttp/blob/71427d373bfd449f80178792fe231f60e4c972db/buildSrc/src/main/kotlin/deps.kt#L24
27-
*/
28-
add("gr8Classpath", "org.conscrypt:conscrypt-openjdk-uber:2.5.2")
20+
val shadowedDependencies = configurations.create("shadowedDependencies")
2921

30-
add("shade", project(":apollo-gradle-plugin-external"))
22+
dependencies {
23+
add(shadowedDependencies.name, project(":apollo-gradle-plugin-external"))
3124

3225
testImplementation(project(":apollo-ast"))
3326
testImplementation(libs.junit)
@@ -45,63 +38,35 @@ dependencies {
4538
testImplementation(libs.slf4j.nop.get().toString()) {
4639
because("jetty uses SL4F")
4740
}
48-
4941
}
5042

43+
5144
if (relocateJar) {
5245
gr8 {
53-
val shadowedJar = create("shadow") {
54-
proguardFile("rules.pro")
55-
configuration("shade")
56-
classPathConfiguration("gr8Classpath")
57-
58-
exclude(".*MANIFEST.MF")
59-
exclude("META-INF/versions/9/module-info\\.class")
60-
exclude("META-INF/kotlin-stdlib.*\\.kotlin_module")
61-
62-
// Remove the following error:
63-
// /Users/mbonnin/.m2/repository/com/apollographql/apollo/apollo-gradle-plugin/3.3.3-SNAPSHOT/apollo-gradle-plugin-3.3.3-SNAPSHOT.jar!/META-INF/kotlinpoet.kotlin_module:
64-
// Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.7.1,
65-
// expected version is 1.5.1.
66-
exclude("META-INF/kotlinpoet.kotlin_module")
67-
68-
//Remove the following error:
69-
// /Users/mbonnin/git/test-gradle-7-4/src/main/kotlin/Main.kt: (2, 5): Class 'kotlin.Unit' was compiled
70-
// with an incompatible version of Kotlin. The binary version of its metadata is 1.7.1, expected version
71-
// is 1.5.1.
72-
exclude("kotlin/Unit.class")
73-
74-
// Remove proguard rules from dependencies, we'll manage them ourselves
75-
exclude("META-INF/proguard/.*")
76-
46+
val shadowedJar = create("default") {
47+
addProgramJarsFrom(shadowedDependencies)
48+
addProgramJarsFrom(tasks.getByName("jar"))
49+
r8Version("887704078a06fc0090e7772c921a30602bf1a49f")
7750
systemClassesToolchain {
78-
languageVersion.set(JavaLanguageVersion.of(8))
51+
languageVersion.set(JavaLanguageVersion.of(jvmTarget))
7952
}
53+
proguardFile("rules.pro")
54+
registerFilterTransform(listOf(".*/impldep/META-INF/versions/.*"))
8055
}
8156

82-
// The java-gradle-plugin adds `gradleApi()` to the `api` implementation but it contains some JDK15 bytecode at
83-
// org/gradle/internal/impldep/META-INF/versions/15/org/bouncycastle/jcajce/provider/asymmetric/edec/SignatureSpi$EdDSA.class:
84-
// java.lang.IllegalArgumentException: Unsupported class file major version 59
85-
// So remove it
86-
val apiDependencies = project.configurations.getByName("api").dependencies
87-
apiDependencies.firstOrNull {
88-
it is FileCollectionDependency
89-
}.let {
90-
apiDependencies.remove(it)
91-
}
92-
57+
removeGradleApiFromApi()
9358
configurations.named("compileOnly").configure {
94-
extendsFrom(shadeConfiguration)
59+
extendsFrom(shadowedDependencies)
9560
}
9661
configurations.named("testImplementation").configure {
97-
extendsFrom(shadeConfiguration)
62+
extendsFrom(shadowedDependencies)
9863
}
9964

10065
replaceOutgoingJar2(shadowedJar)
10166
}
10267
} else {
10368
configurations.named("implementation").configure {
104-
extendsFrom(shadeConfiguration)
69+
extendsFrom(shadowedDependencies)
10570
}
10671
}
10772

@@ -112,7 +77,6 @@ fun replaceOutgoingJar2(newJar: Any) {
11277
it.name == "apollo-gradle-plugin" && it.type == "jar" && it.classifier.isNullOrEmpty()
11378
}
11479
if (removed) {
115-
11680
artifact(newJar) {
11781
// Pom and maven consumers do not like the `-all` or `-shadowed` classifiers
11882
classifier = ""
Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#noinspection ShrinkerUnresolvedReference
2+
13
# Keep kotlin metadata so that the Kotlin compiler knows about top level functions such as
24
# Line 1: import com.apollographql.apollo.gradle.api.kotlinMultiplatformExtension
35
# ^ Unresolved reference: kotlinMultiplatformExtension
@@ -12,7 +14,7 @@
1214
# 'Declaration of property alwaysGenerateTypesMatching does not include any type arguments in its property type interface org.gradle.api.provider.SetProperty'
1315
-keepattributes Signature,InnerClasses,EnclosingMethod
1416
# Similarly, Gradle needs the @Inject annotations
15-
-keepattributes *Annotation*
17+
-keepattributes RuntimeVisible*Annotation*
1618
# For debug
1719
-keepattributes SourceFile,LineNumberTable
1820

@@ -24,34 +26,18 @@
2426

2527
# Keep apollo-annotations for ApolloExperimental
2628
-keep class com.apollographql.apollo.annotations.** { *; }
27-
# We don't need to keep apollo-api but it's been here for a while and some folks might depend on it so keep it
28-
-keep class com.apollographql.apollo.api.** { *; }
29-
# Keep compiler API as it's used in workers and for things like OperationOutputGenerator
29+
# Keep the plugin API as it's used from build scripts
30+
-keep class com.apollographql.apollo.gradle.api.** { *; }
31+
-keep interface com.apollographql.apollo.gradle.api.** { *; }
32+
# And also the compiler API as it's used transitively for things like OperationOutputGenerator
3033
-keep class com.apollographql.apollo.compiler.** { *; }
3134
-keep interface com.apollographql.apollo.compiler.** { *; }
3235
-keep enum com.apollographql.apollo.compiler.** { *; }
3336
# Schema is used in a worker: https://github.com/apollographql/apollo-kotlin/blob/198480d8b0b24c01f4d11da0b1e9fa9c97062c5c/libraries/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo/gradle/internal/ApolloGenerateSourcesTask.kt#L131
3437
-keep class com.apollographql.apollo.ast.Schema { *; }
35-
# Keep the plugin API as it's used from build scripts
36-
-keep class com.apollographql.apollo.gradle.api.** { *; }
37-
-keep interface com.apollographql.apollo.gradle.api.** { *; }
38-
-keep enum com.apollographql.apollo.gradle.api.** { *; }
39-
# Keep the ApolloPlugin entry point and everything in internal too (not sure why this is needed, ApolloGenerateSourcesTask is shrunk else)
38+
# Keep the ApolloPlugin entry point and everything in internal too because we have ApolloPlugin there
4039
-keep class com.apollographql.apollo.gradle.internal.** { *; }
4140

42-
-keep class org.gradle.api.** { *; }
43-
-keep interface org.gradle.api.** { *; }
44-
-keep enum org.gradle.api.** { *; }
45-
46-
# OkHttp has a rule that keeps PublicSuffixDatabase. It's not clear if we need it or not. For now, keep the rule. This has the
47-
# effect of actually keeping okhttp3.internal.publicsuffix.PublicSuffixDatabase. If this ever clashes with another version of
48-
# okhttp, a solution would be to uncomment the line below and use mapping.txt to relocate okhttp3/internal/publicsuffix/publicsuffixes.gz
49-
# inside the zip
50-
# See https://github.com/square/okhttp/pull/3421 and https://github.com/square/okhttp/pull/3647
51-
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase
52-
53-
# Makes it easier to debug on MacOS case-insensitive filesystem when unzipping the jars
54-
-dontusemixedcaseclassnames
5541
# Keep class names to make debugging easier
5642
-dontobfuscate
5743
-repackageclasses com.apollographql.apollo.relocated
@@ -60,4 +46,10 @@
6046
-allowaccessmodification
6147

6248
# The Gradle API jar and other compileOnly dependencies aren't added to the classpath, ignore the missing symbols
63-
-dontwarn **
49+
# I tried adding them but they duplicate a lot of the program classes and trigger errors in R8.
50+
# A future version could try to remove the intersection between the compileOnly classpath and the runtime one
51+
-dontwarn org.gradle.**
52+
-dontwarn org.jetbrains.kotlin.gradle.**
53+
-dontwarn com.android.build.gradle.**
54+
-dontwarn com.android.builder.**
55+
-dontwarn javax.inject.Inject

0 commit comments

Comments
 (0)