Skip to content

Commit 5e780aa

Browse files
authored
Track @ApolloExperimental symbols in public API (#6416)
* Fix applying OptIn options * fix merge
1 parent f6c5eb8 commit 5e780aa

File tree

22 files changed

+1742
-51
lines changed

22 files changed

+1742
-51
lines changed

build-logic/src/main/kotlin/CompilerOptions.kt

+11-25
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import com.android.build.gradle.BaseExtension
22
import org.gradle.api.JavaVersion
33
import org.gradle.api.Project
4-
import org.gradle.api.artifacts.ExternalDependency
54
import org.gradle.api.plugins.JavaPluginExtension
65
import org.gradle.api.tasks.compile.JavaCompile
76
import org.gradle.api.tasks.testing.Test
@@ -17,12 +16,16 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
1716
import org.jetbrains.kotlin.gradle.dsl.KotlinNativeCompilerOptions
1817
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
1918
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
20-
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
2119

2220
/**
2321
* @param target the JVM version we want to be compatible with (bytecode + bootstrap classpath)
2422
*/
25-
fun KotlinCommonCompilerOptions.configure(target: Int, kotlinCompilerOptions: KotlinCompilerOptions, isAndroid: Boolean) {
23+
fun KotlinCommonCompilerOptions.configure(
24+
target: Int,
25+
kotlinCompilerOptions: KotlinCompilerOptions,
26+
isAndroid: Boolean,
27+
optIns: List<String>
28+
) {
2629
val actualTarget = when {
2730
isAndroid -> {
2831
// https://blog.blundellapps.co.uk/setting-jdk-level-in-android-gradle-builds/
@@ -35,13 +38,9 @@ fun KotlinCommonCompilerOptions.configure(target: Int, kotlinCompilerOptions: Ko
3538

3639
freeCompilerArgs.add("-Xexpect-actual-classes")
3740

38-
/**
39-
* Inside our own codebase, we opt-in ApolloInternal and ApolloExperimental
40-
* We might want to do something more precise where we only opt-in for libraries but still require integration tests to opt-in with more granularity
41-
*/
42-
freeCompilerArgs.add("-opt-in=kotlin.RequiresOptIn")
43-
freeCompilerArgs.add("-opt-in=com.apollographql.apollo.annotations.ApolloExperimental")
44-
freeCompilerArgs.add("-opt-in=com.apollographql.apollo.annotations.ApolloInternal")
41+
optIns.forEach {
42+
freeCompilerArgs.add("-opt-in=$it")
43+
}
4544

4645
apiVersion.set(kotlinCompilerOptions.version)
4746
languageVersion.set(kotlinCompilerOptions.version)
@@ -106,12 +105,12 @@ val Project.androidExtensionOrNull: BaseExtension?
106105
return (extensions.findByName("android") as? BaseExtension)
107106
}
108107

109-
fun Project.configureJavaAndKotlinCompilers(jvmTarget: Int?, kotlinCompilerOptions: KotlinCompilerOptions) {
108+
fun Project.configureJavaAndKotlinCompilers(jvmTarget: Int?, kotlinCompilerOptions: KotlinCompilerOptions, optIns: List<String>) {
110109
@Suppress("NAME_SHADOWING")
111110
val jvmTarget = jvmTarget ?: 8
112111

113112
kotlinExtensionOrNull?.forEachCompilerOptions { isAndroid ->
114-
configure(jvmTarget, kotlinCompilerOptions, isAndroid)
113+
configure(jvmTarget, kotlinCompilerOptions, isAndroid, optIns)
115114
}
116115
project.tasks.withType(JavaCompile::class.java).configureEach {
117116
// For JVM only modules, this dictates the "org.gradle.jvm.version" Gradle attribute
@@ -131,11 +130,6 @@ fun Project.configureJavaAndKotlinCompilers(jvmTarget: Int?, kotlinCompilerOptio
131130
}
132131
}
133132

134-
(kotlinExtensionOrNull as? KotlinMultiplatformExtension)?.sourceSets?.configureEach {
135-
languageSettings.optIn("com.apollographql.apollo.annotations.ApolloExperimental")
136-
languageSettings.optIn("com.apollographql.apollo.annotations.ApolloInternal")
137-
}
138-
139133
/**
140134
* We're using a toolchain to ensure build cache can be shared. Many tasks, including compileJava use the
141135
* java version as input and using different JDKs will trash the cache.
@@ -160,14 +154,6 @@ fun setTestToolchain(project: Project, test: Test, javaVersion: Int) {
160154

161155
}
162156

163-
internal fun Project.addOptIn(vararg annotations: String) {
164-
tasks.withType(KotlinCompilationTask::class.java).configureEach {
165-
compilerOptions {
166-
freeCompilerArgs.addAll(annotations.map { "-opt-in=$it" })
167-
}
168-
}
169-
}
170-
171157
fun Project.allWarningsAsErrors(allWarningsAsErrors: Boolean) {
172158
kotlinExtensionOrNull?.forEachCompilerOptions {
173159
this.allWarningsAsErrors.set(allWarningsAsErrors)

build-logic/src/main/kotlin/api.kt

+16-10
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ import org.gradle.api.tasks.TaskProvider
66
import org.gradle.jvm.tasks.Jar
77
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
88
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
9-
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension
10-
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootPlugin
11-
import org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinNpmInstallTask
129

1310
class AndroidOptions(
1411
val withCompose: Boolean,
@@ -37,10 +34,15 @@ fun Project.apolloLibrary(
3734
configureAndroid(namespace, androidOptions)
3835
}
3936
commonSetup()
40-
configureJavaAndKotlinCompilers(jvmTarget, kotlinCompilerOptions)
4137

42-
addOptIn(
43-
"com.apollographql.apollo.annotations.ApolloInternal"
38+
configureJavaAndKotlinCompilers(
39+
jvmTarget,
40+
kotlinCompilerOptions,
41+
listOf(
42+
"kotlin.RequiresOptIn",
43+
"com.apollographql.apollo.annotations.ApolloInternal",
44+
"com.apollographql.apollo.annotations.ApolloExperimental"
45+
)
4446
)
4547

4648
if (publish) {
@@ -102,10 +104,14 @@ fun Project.apolloTest(
102104
kotlinCompilerOptions: KotlinCompilerOptions = KotlinCompilerOptions(),
103105
) {
104106
commonSetup()
105-
configureJavaAndKotlinCompilers(null, kotlinCompilerOptions)
106-
addOptIn(
107-
"com.apollographql.apollo.annotations.ApolloExperimental",
108-
"com.apollographql.apollo.annotations.ApolloInternal",
107+
configureJavaAndKotlinCompilers(
108+
null,
109+
kotlinCompilerOptions,
110+
listOf(
111+
"kotlin.RequiresOptIn",
112+
"com.apollographql.apollo.annotations.ApolloExperimental",
113+
"com.apollographql.apollo.annotations.ApolloInternal"
114+
)
109115
)
110116

111117
if (extensions.findByName("kotlin") is KotlinMultiplatformExtension) {

build.gradle.kts

-6
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,6 @@ configure<kotlinx.validation.ApiValidationExtension> {
139139
)
140140

141141
ignoredProjects.add("intellij-plugin")
142-
143-
nonPublicMarkers.addAll(
144-
listOf(
145-
"com.apollographql.apollo.annotations.ApolloExperimental",
146-
)
147-
)
148142
}
149143

150144
tasks.register("rmbuild") {

0 commit comments

Comments
 (0)