2020-10-16 17:18:11 +02:00
|
|
|
/*
|
2021-03-09 10:15:27 +01:00
|
|
|
* Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
|
2020-10-16 17:18:11 +02:00
|
|
|
* SPDX-License-Identifier: GPL-3.0-only
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import com.android.build.gradle.TestedExtension
|
2020-11-15 09:34:14 +01:00
|
|
|
import com.android.build.gradle.internal.dsl.BaseAppModuleExtension
|
2020-10-16 17:18:11 +02:00
|
|
|
import com.android.build.gradle.internal.plugins.AppPlugin
|
|
|
|
|
import com.android.build.gradle.internal.plugins.LibraryPlugin
|
|
|
|
|
import org.gradle.api.Plugin
|
|
|
|
|
import org.gradle.api.Project
|
|
|
|
|
import org.gradle.api.plugins.JavaLibraryPlugin
|
|
|
|
|
import org.gradle.api.plugins.JavaPlugin
|
|
|
|
|
import org.gradle.api.tasks.compile.JavaCompile
|
2021-04-17 19:03:00 +02:00
|
|
|
import org.gradle.kotlin.dsl.configure
|
2020-10-16 17:18:11 +02:00
|
|
|
import org.gradle.kotlin.dsl.getByType
|
|
|
|
|
import org.gradle.kotlin.dsl.withType
|
2021-04-15 10:41:43 +02:00
|
|
|
import org.gradle.plugins.signing.SigningExtension
|
|
|
|
|
import org.gradle.plugins.signing.SigningPlugin
|
2021-04-17 19:03:00 +02:00
|
|
|
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
|
2021-06-01 11:35:05 +02:00
|
|
|
import org.jetbrains.kotlin.gradle.internal.Kapt3GradleSubplugin
|
2021-04-17 19:03:00 +02:00
|
|
|
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper
|
|
|
|
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
2020-10-16 17:18:11 +02:00
|
|
|
|
|
|
|
|
class PasswordStorePlugin : Plugin<Project> {
|
|
|
|
|
|
|
|
|
|
override fun apply(project: Project) {
|
|
|
|
|
project.configureForAllProjects()
|
|
|
|
|
|
|
|
|
|
if (project.isRoot) {
|
|
|
|
|
project.configureForRootProject()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
project.plugins.all {
|
|
|
|
|
when (this) {
|
|
|
|
|
is JavaPlugin, is JavaLibraryPlugin -> {
|
|
|
|
|
project.tasks.withType<JavaCompile> {
|
|
|
|
|
options.compilerArgs.add("-Xlint:unchecked")
|
|
|
|
|
options.isDeprecation = true
|
2021-05-27 00:59:13 +02:00
|
|
|
options.isWarnings = true
|
2021-03-09 10:23:11 +01:00
|
|
|
}
|
2020-10-16 17:18:11 +02:00
|
|
|
}
|
2020-11-15 09:34:14 +01:00
|
|
|
is LibraryPlugin -> {
|
|
|
|
|
project.extensions.getByType<TestedExtension>().configureCommonAndroidOptions()
|
2021-04-17 19:03:00 +02:00
|
|
|
project.configureExplicitApi()
|
2021-07-19 13:01:37 +02:00
|
|
|
project.configureSlimTests()
|
2020-11-15 09:34:14 +01:00
|
|
|
}
|
2020-10-16 17:18:11 +02:00
|
|
|
is AppPlugin -> {
|
2021-05-07 12:57:55 +02:00
|
|
|
project
|
|
|
|
|
.extensions
|
|
|
|
|
.getByType<BaseAppModuleExtension>()
|
|
|
|
|
.configureAndroidApplicationOptions(project)
|
2020-11-15 09:34:14 +01:00
|
|
|
project.extensions.getByType<BaseAppModuleExtension>().configureBuildSigning(project)
|
2020-10-16 17:18:11 +02:00
|
|
|
project.extensions.getByType<TestedExtension>().configureCommonAndroidOptions()
|
2021-07-19 13:01:37 +02:00
|
|
|
project.configureSlimTests()
|
2020-10-16 17:18:11 +02:00
|
|
|
}
|
2021-04-15 10:41:43 +02:00
|
|
|
is SigningPlugin -> {
|
|
|
|
|
project.extensions.getByType<SigningExtension>().configureBuildSigning()
|
|
|
|
|
}
|
2021-04-17 19:03:00 +02:00
|
|
|
is KotlinPluginWrapper -> {
|
|
|
|
|
project.configureExplicitApi()
|
|
|
|
|
}
|
2021-06-01 11:35:05 +02:00
|
|
|
is Kapt3GradleSubplugin -> {
|
|
|
|
|
project.configureKapt()
|
|
|
|
|
}
|
2021-03-09 10:23:11 +01:00
|
|
|
}
|
2020-10-16 17:18:11 +02:00
|
|
|
}
|
2021-03-09 10:23:11 +01:00
|
|
|
}
|
2021-04-17 19:03:00 +02:00
|
|
|
|
|
|
|
|
private fun Project.configureExplicitApi() {
|
2021-08-13 15:10:34 +02:00
|
|
|
val project = this
|
2021-04-17 19:03:00 +02:00
|
|
|
tasks.withType<KotlinCompile> {
|
2021-08-13 15:10:34 +02:00
|
|
|
if (!name.contains("test", ignoreCase = true)) {
|
|
|
|
|
project.configure<KotlinProjectExtension> { explicitApi() }
|
|
|
|
|
kotlinOptions { freeCompilerArgs += listOf("-Xexplicit-api=strict") }
|
|
|
|
|
}
|
2021-04-17 19:03:00 +02:00
|
|
|
}
|
|
|
|
|
}
|
2020-10-16 17:18:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private val Project.isRoot
|
|
|
|
|
get() = this == this.rootProject
|