From a13176a23dba82e29474cb4f7b5cbf6f49b3eb53 Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sat, 17 Apr 2021 22:33:00 +0530 Subject: build: enable explicit API automatically on all library projects Signed-off-by: Harsh Shandilya --- autofill-parser/build.gradle.kts | 4 ---- buildSrc/src/main/java/PasswordStorePlugin.kt | 15 +++++++++++++++ openpgp-ktx/build.gradle.kts | 4 ---- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/autofill-parser/build.gradle.kts b/autofill-parser/build.gradle.kts index 928e3828..c029b65c 100644 --- a/autofill-parser/build.gradle.kts +++ b/autofill-parser/build.gradle.kts @@ -16,10 +16,6 @@ android { versionName = "2.0" consumerProguardFiles("consumer-rules.pro") } - - kotlin { explicitApi() } - - kotlinOptions { freeCompilerArgs = freeCompilerArgs + listOf("-Xexplicit-api=strict") } } dependencies { diff --git a/buildSrc/src/main/java/PasswordStorePlugin.kt b/buildSrc/src/main/java/PasswordStorePlugin.kt index 21496f8f..f4923e04 100644 --- a/buildSrc/src/main/java/PasswordStorePlugin.kt +++ b/buildSrc/src/main/java/PasswordStorePlugin.kt @@ -14,10 +14,14 @@ import org.gradle.api.Project import org.gradle.api.plugins.JavaLibraryPlugin import org.gradle.api.plugins.JavaPlugin import org.gradle.api.tasks.compile.JavaCompile +import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.getByType import org.gradle.kotlin.dsl.withType import org.gradle.plugins.signing.SigningExtension import org.gradle.plugins.signing.SigningPlugin +import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension +import org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile class PasswordStorePlugin : Plugin { @@ -38,6 +42,7 @@ class PasswordStorePlugin : Plugin { } is LibraryPlugin -> { project.extensions.getByType().configureCommonAndroidOptions() + project.configureExplicitApi() } is AppPlugin -> { project.extensions.getByType().configureAndroidApplicationOptions(project) @@ -50,9 +55,19 @@ class PasswordStorePlugin : Plugin { is SigningPlugin -> { project.extensions.getByType().configureBuildSigning() } + is KotlinPluginWrapper -> { + project.configureExplicitApi() + } } } } + + private fun Project.configureExplicitApi() { + configure { explicitApi() } + tasks.withType { + kotlinOptions { freeCompilerArgs = freeCompilerArgs + listOf("-Xexplicit-api=strict") } + } + } } private val Project.isRoot diff --git a/openpgp-ktx/build.gradle.kts b/openpgp-ktx/build.gradle.kts index 90a89501..79e083b5 100644 --- a/openpgp-ktx/build.gradle.kts +++ b/openpgp-ktx/build.gradle.kts @@ -14,10 +14,6 @@ android { defaultConfig { consumerProguardFiles("consumer-proguard-rules.pro") } buildFeatures.aidl = true - - kotlin { explicitApi() } - - kotlinOptions { freeCompilerArgs = freeCompilerArgs + listOf("-Xexplicit-api=strict") } } dependencies { implementation(libs.kotlin.coroutines.core) } -- cgit v1.2.3