1
1
import com.android.build.gradle.BaseExtension
2
2
import org.gradle.api.JavaVersion
3
3
import org.gradle.api.Project
4
- import org.gradle.api.artifacts.ExternalDependency
5
4
import org.gradle.api.plugins.JavaPluginExtension
6
5
import org.gradle.api.tasks.compile.JavaCompile
7
6
import org.gradle.api.tasks.testing.Test
@@ -17,12 +16,16 @@ import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
17
16
import org.jetbrains.kotlin.gradle.dsl.KotlinNativeCompilerOptions
18
17
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
19
18
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
20
- import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
21
19
22
20
/* *
23
21
* @param target the JVM version we want to be compatible with (bytecode + bootstrap classpath)
24
22
*/
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
+ ) {
26
29
val actualTarget = when {
27
30
isAndroid -> {
28
31
// https://blog.blundellapps.co.uk/setting-jdk-level-in-android-gradle-builds/
@@ -35,13 +38,9 @@ fun KotlinCommonCompilerOptions.configure(target: Int, kotlinCompilerOptions: Ko
35
38
36
39
freeCompilerArgs.add(" -Xexpect-actual-classes" )
37
40
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
+ }
45
44
46
45
apiVersion.set(kotlinCompilerOptions.version)
47
46
languageVersion.set(kotlinCompilerOptions.version)
@@ -106,12 +105,12 @@ val Project.androidExtensionOrNull: BaseExtension?
106
105
return (extensions.findByName(" android" ) as ? BaseExtension )
107
106
}
108
107
109
- fun Project.configureJavaAndKotlinCompilers (jvmTarget : Int? , kotlinCompilerOptions : KotlinCompilerOptions ) {
108
+ fun Project.configureJavaAndKotlinCompilers (jvmTarget : Int? , kotlinCompilerOptions : KotlinCompilerOptions , optIns : List < String > ) {
110
109
@Suppress(" NAME_SHADOWING" )
111
110
val jvmTarget = jvmTarget ? : 8
112
111
113
112
kotlinExtensionOrNull?.forEachCompilerOptions { isAndroid ->
114
- configure(jvmTarget, kotlinCompilerOptions, isAndroid)
113
+ configure(jvmTarget, kotlinCompilerOptions, isAndroid, optIns )
115
114
}
116
115
project.tasks.withType(JavaCompile ::class .java).configureEach {
117
116
// For JVM only modules, this dictates the "org.gradle.jvm.version" Gradle attribute
@@ -131,11 +130,6 @@ fun Project.configureJavaAndKotlinCompilers(jvmTarget: Int?, kotlinCompilerOptio
131
130
}
132
131
}
133
132
134
- (kotlinExtensionOrNull as ? KotlinMultiplatformExtension )?.sourceSets?.configureEach {
135
- languageSettings.optIn(" com.apollographql.apollo.annotations.ApolloExperimental" )
136
- languageSettings.optIn(" com.apollographql.apollo.annotations.ApolloInternal" )
137
- }
138
-
139
133
/* *
140
134
* We're using a toolchain to ensure build cache can be shared. Many tasks, including compileJava use the
141
135
* java version as input and using different JDKs will trash the cache.
@@ -160,14 +154,6 @@ fun setTestToolchain(project: Project, test: Test, javaVersion: Int) {
160
154
161
155
}
162
156
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
-
171
157
fun Project.allWarningsAsErrors (allWarningsAsErrors : Boolean ) {
172
158
kotlinExtensionOrNull?.forEachCompilerOptions {
173
159
this .allWarningsAsErrors.set(allWarningsAsErrors)
0 commit comments