build: enable explicit API automatically on all library projects

Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
Harsh Shandilya 2021-04-17 22:33:00 +05:30
parent cada2353c1
commit a13176a23d
No known key found for this signature in database
GPG key ID: 366D7BBAD1031E80
3 changed files with 15 additions and 8 deletions

View file

@ -16,10 +16,6 @@ android {
versionName = "2.0"
consumerProguardFiles("consumer-rules.pro")
}
kotlin { explicitApi() }
kotlinOptions { freeCompilerArgs = freeCompilerArgs + listOf("-Xexplicit-api=strict") }
}
dependencies {

View file

@ -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<Project> {
@ -38,6 +42,7 @@ class PasswordStorePlugin : Plugin<Project> {
}
is LibraryPlugin -> {
project.extensions.getByType<TestedExtension>().configureCommonAndroidOptions()
project.configureExplicitApi()
}
is AppPlugin -> {
project.extensions.getByType<BaseAppModuleExtension>().configureAndroidApplicationOptions(project)
@ -50,9 +55,19 @@ class PasswordStorePlugin : Plugin<Project> {
is SigningPlugin -> {
project.extensions.getByType<SigningExtension>().configureBuildSigning()
}
is KotlinPluginWrapper -> {
project.configureExplicitApi()
}
}
}
}
private fun Project.configureExplicitApi() {
configure<KotlinProjectExtension> { explicitApi() }
tasks.withType<KotlinCompile> {
kotlinOptions { freeCompilerArgs = freeCompilerArgs + listOf("-Xexplicit-api=strict") }
}
}
}
private val Project.isRoot

View file

@ -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) }