aboutsummaryrefslogtreecommitdiff
path: root/buildSrc
diff options
context:
space:
mode:
Diffstat (limited to 'buildSrc')
-rw-r--r--buildSrc/build.gradle.kts21
-rw-r--r--buildSrc/buildDependencies.gradle11
-rw-r--r--buildSrc/src/main/java/BaseProjectConfig.kt83
-rw-r--r--buildSrc/src/main/java/BinaryCompatibilityValidator.kt16
-rw-r--r--buildSrc/src/main/java/Dependencies.kt15
-rw-r--r--buildSrc/src/main/java/KotlinCompilerArgs.kt8
-rw-r--r--buildSrc/src/main/java/PasswordStorePlugin.kt44
7 files changed, 186 insertions, 12 deletions
diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts
index 3457e2c2..2c721629 100644
--- a/buildSrc/build.gradle.kts
+++ b/buildSrc/build.gradle.kts
@@ -1,11 +1,30 @@
+apply(from = "buildDependencies.gradle")
+val build: Map<Any, Any> by extra
+
plugins {
`kotlin-dsl`
}
repositories {
- jcenter()
+ google()
+ gradlePluginPortal()
}
kotlinDslPluginOptions {
experimentalWarning.set(false)
}
+
+gradlePlugin {
+ plugins {
+ register("aps") {
+ id = "aps-plugin"
+ implementationClass = "PasswordStorePlugin"
+ }
+ }
+}
+
+dependencies {
+ implementation(build.getValue("kotlinGradlePlugin"))
+ implementation(build.getValue("androidGradlePlugin"))
+ implementation(build.getValue("binaryCompatibilityValidator"))
+}
diff --git a/buildSrc/buildDependencies.gradle b/buildSrc/buildDependencies.gradle
new file mode 100644
index 00000000..d9b2bbb7
--- /dev/null
+++ b/buildSrc/buildDependencies.gradle
@@ -0,0 +1,11 @@
+rootProject.ext.versions = [
+ agp : '4.1.0',
+ kotlin : '1.4.10',
+ binary_compatibility_validator : '0.2.3',
+]
+
+rootProject.ext.build = [
+ androidGradlePlugin : "com.android.tools.build:gradle:${versions.agp}",
+ kotlinGradlePlugin : "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}",
+ binaryCompatibilityValidator : "org.jetbrains.kotlinx:binary-compatibility-validator:${versions.binary_compatibility_validator}",
+]
diff --git a/buildSrc/src/main/java/BaseProjectConfig.kt b/buildSrc/src/main/java/BaseProjectConfig.kt
new file mode 100644
index 00000000..3b2a3f3b
--- /dev/null
+++ b/buildSrc/src/main/java/BaseProjectConfig.kt
@@ -0,0 +1,83 @@
+/*
+ * Copyright © 2014-2020 The Android Password Store Authors. All Rights Reserved.
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+import com.android.build.gradle.TestedExtension
+import org.gradle.api.JavaVersion
+import org.gradle.api.Project
+import org.gradle.api.tasks.Delete
+import org.gradle.api.tasks.testing.Test
+import org.gradle.api.tasks.testing.logging.TestLogEvent
+import org.gradle.api.tasks.wrapper.Wrapper
+import org.gradle.kotlin.dsl.repositories
+import org.gradle.kotlin.dsl.withType
+import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
+
+/**
+ * Configure root project.
+ * Note that classpath dependencies still need to be defined in the `buildscript` block in the top-level build.gradle.kts file.
+ */
+internal fun Project.configureForRootProject() {
+ // register task for cleaning the build directory in the root project
+ tasks.register("clean", Delete::class.java) {
+ delete(rootProject.buildDir)
+ }
+ tasks.withType<Wrapper> {
+ gradleVersion = "6.7"
+ distributionType = Wrapper.DistributionType.ALL
+ distributionSha256Sum = "0080de8491f0918e4f529a6db6820fa0b9e818ee2386117f4394f95feb1d5583"
+ }
+ configureBinaryCompatibilityValidator()
+}
+
+/**
+ * Configure all projects including the root project
+ */
+internal fun Project.configureForAllProjects() {
+ repositories {
+ google()
+ jcenter()
+ maven { setUrl("https://jitpack.io") }
+ }
+ tasks.withType<KotlinCompile> {
+ kotlinOptions {
+ jvmTarget = JavaVersion.VERSION_1_8.toString()
+ freeCompilerArgs = freeCompilerArgs + additionalCompilerArgs
+ languageVersion = "1.4"
+ }
+ }
+ tasks.withType<Test> {
+ maxParallelForks = Runtime.getRuntime().availableProcessors() * 2
+ testLogging {
+ events(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED)
+ }
+ }
+}
+
+/**
+ * Apply baseline configurations for all Android projects (Application and Library).
+ */
+@Suppress("UnstableApiUsage")
+internal fun TestedExtension.configureCommonAndroidOptions() {
+ compileSdkVersion(29)
+
+ defaultConfig {
+ minSdkVersion(23)
+ targetSdkVersion(29)
+ }
+
+ packagingOptions {
+ exclude("**/*.version")
+ exclude("**/*.txt")
+ exclude("**/*.kotlin_module")
+ exclude("**/plugin.properties")
+ }
+
+ compileOptions {
+ sourceCompatibility = JavaVersion.VERSION_1_8
+ targetCompatibility = JavaVersion.VERSION_1_8
+ }
+
+ testOptions.animationsDisabled = true
+}
diff --git a/buildSrc/src/main/java/BinaryCompatibilityValidator.kt b/buildSrc/src/main/java/BinaryCompatibilityValidator.kt
new file mode 100644
index 00000000..b622513c
--- /dev/null
+++ b/buildSrc/src/main/java/BinaryCompatibilityValidator.kt
@@ -0,0 +1,16 @@
+/*
+ * Copyright © 2014-2020 The Android Password Store Authors. All Rights Reserved.
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+import kotlinx.validation.ApiValidationExtension
+import org.gradle.api.Project
+import org.gradle.kotlin.dsl.configure
+
+internal fun Project.configureBinaryCompatibilityValidator() {
+ extensions.configure<ApiValidationExtension> {
+ ignoredProjects = mutableSetOf(
+ "app"
+ )
+ }
+}
diff --git a/buildSrc/src/main/java/Dependencies.kt b/buildSrc/src/main/java/Dependencies.kt
index 0f8c903d..715ec811 100644
--- a/buildSrc/src/main/java/Dependencies.kt
+++ b/buildSrc/src/main/java/Dependencies.kt
@@ -5,13 +5,6 @@
private const val KOTLIN_VERSION = "1.4.10"
-object Plugins {
-
- const val agp = "com.android.tools.build:gradle:4.0.2"
- const val binaryCompatibilityValidator = "org.jetbrains.kotlinx:binary-compatibility-validator:0.2.3"
- const val kotlin = "org.jetbrains.kotlin:kotlin-gradle-plugin:$KOTLIN_VERSION"
-}
-
object Dependencies {
object Kotlin {
object Coroutines {
@@ -28,7 +21,7 @@ object Dependencies {
const val activity_ktx = "androidx.activity:activity-ktx:1.2.0-beta01"
const val annotation = "androidx.annotation:annotation:1.1.0"
- const val autofill = "androidx.autofill:autofill:1.1.0-alpha02"
+ const val autofill = "androidx.autofill:autofill:1.1.0-beta01"
const val appcompat = "androidx.appcompat:appcompat:1.3.0-alpha02"
const val biometric = "androidx.biometric:biometric:1.1.0-beta01"
const val constraint_layout = "androidx.constraintlayout:constraintlayout:2.0.2"
@@ -38,7 +31,7 @@ object Dependencies {
const val lifecycle_common = "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion"
const val lifecycle_livedata_ktx = "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion"
const val lifecycle_viewmodel_ktx = "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion"
- const val material = "com.google.android.material:material:1.3.0-alpha02"
+ const val material = "com.google.android.material:material:1.3.0-alpha03"
const val preference = "androidx.preference:preference:1.1.1"
const val recycler_view = "androidx.recyclerview:recyclerview:1.2.0-alpha06"
const val recycler_view_selection = "androidx.recyclerview:recyclerview-selection:1.1.0-rc03"
@@ -72,12 +65,12 @@ object Dependencies {
object NonFree {
- const val google_play_auth_api_phone = "com.google.android.gms:play-services-auth-api-phone:17.4.0"
+ const val google_play_auth_api_phone = "com.google.android.gms:play-services-auth-api-phone:17.5.0"
}
object Testing {
- const val junit = "junit:junit:4.13"
+ const val junit = "junit:junit:4.13.1"
const val kotlin_test_junit = "org.jetbrains.kotlin:kotlin-test-junit:$KOTLIN_VERSION"
object AndroidX {
diff --git a/buildSrc/src/main/java/KotlinCompilerArgs.kt b/buildSrc/src/main/java/KotlinCompilerArgs.kt
new file mode 100644
index 00000000..b4931917
--- /dev/null
+++ b/buildSrc/src/main/java/KotlinCompilerArgs.kt
@@ -0,0 +1,8 @@
+/*
+ * Copyright © 2014-2020 The Android Password Store Authors. All Rights Reserved.
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+internal val additionalCompilerArgs = listOf(
+ "-Xopt-in=kotlin.RequiresOptIn"
+)
diff --git a/buildSrc/src/main/java/PasswordStorePlugin.kt b/buildSrc/src/main/java/PasswordStorePlugin.kt
new file mode 100644
index 00000000..37a23b02
--- /dev/null
+++ b/buildSrc/src/main/java/PasswordStorePlugin.kt
@@ -0,0 +1,44 @@
+/*
+ * Copyright © 2014-2020 The Android Password Store Authors. All Rights Reserved.
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+import com.android.build.gradle.TestedExtension
+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
+import org.gradle.kotlin.dsl.getByType
+import org.gradle.kotlin.dsl.withType
+
+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
+ }
+ }
+ is LibraryPlugin,
+ is AppPlugin -> {
+ project.extensions.getByType<TestedExtension>().configureCommonAndroidOptions()
+ }
+ }
+ }
+ }
+}
+
+private val Project.isRoot get() = this == this.rootProject