summaryrefslogtreecommitdiff
path: root/buildSrc/src
diff options
context:
space:
mode:
Diffstat (limited to 'buildSrc/src')
-rw-r--r--buildSrc/src/main/java/KaptConfigs.kt34
-rw-r--r--buildSrc/src/main/java/PasswordStorePlugin.kt9
-rw-r--r--buildSrc/src/main/java/Spotless.kt32
3 files changed, 60 insertions, 15 deletions
diff --git a/buildSrc/src/main/java/KaptConfigs.kt b/buildSrc/src/main/java/KaptConfigs.kt
new file mode 100644
index 00000000..db1c6d5a
--- /dev/null
+++ b/buildSrc/src/main/java/KaptConfigs.kt
@@ -0,0 +1,34 @@
+import org.gradle.api.Project
+import org.gradle.kotlin.dsl.configure
+import org.jetbrains.kotlin.gradle.plugin.KaptExtension
+
+/** Apply default kapt configs to the [Project]. */
+internal fun Project.configureKapt() {
+ extensions.configure<KaptExtension> {
+ javacOptions {
+ if (hasDaggerCompilerDependency) {
+ // https://dagger.dev/dev-guide/compiler-options#fastinit-mode
+ option("-Adagger.fastInit=enabled")
+ // Enable the better, experimental error messages
+ // https://github.com/google/dagger/commit/0d2505a727b54f47b8677f42dd4fc5c1924e37f5
+ option("-Adagger.experimentalDaggerErrorMessages=enabled")
+ // Share test components for when we start leveraging Hilt for tests
+ // https://github.com/google/dagger/releases/tag/dagger-2.34
+ option("-Adagger.hilt.shareTestComponents=true")
+ // KAPT nests errors causing real issues to be suppressed in CI logs
+ option("-Xmaxerrs", 500)
+ // Enables per-module validation for faster error detection
+ // https://github.com/google/dagger/commit/325b516ac6a53d3fc973d247b5231fafda9870a2
+ option("-Adagger.moduleBindingValidation=ERROR")
+ }
+ }
+ }
+ // disable kapt tasks for unit tests
+ tasks
+ .matching { it.name.startsWith("kapt") && it.name.endsWith("UnitTestKotlin") }
+ .configureEach { enabled = false }
+}
+
+private val Project.hasDaggerCompilerDependency: Boolean
+ get() =
+ configurations.any { it.dependencies.any { dependency -> dependency.name == "hilt-compiler" } }
diff --git a/buildSrc/src/main/java/PasswordStorePlugin.kt b/buildSrc/src/main/java/PasswordStorePlugin.kt
index 5db8c893..0705de82 100644
--- a/buildSrc/src/main/java/PasswordStorePlugin.kt
+++ b/buildSrc/src/main/java/PasswordStorePlugin.kt
@@ -7,8 +7,6 @@ import com.android.build.gradle.TestedExtension
import com.android.build.gradle.internal.dsl.BaseAppModuleExtension
import com.android.build.gradle.internal.plugins.AppPlugin
import com.android.build.gradle.internal.plugins.LibraryPlugin
-import com.diffplug.gradle.spotless.SpotlessExtension
-import com.diffplug.gradle.spotless.SpotlessPlugin
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.JavaLibraryPlugin
@@ -20,6 +18,7 @@ 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.internal.Kapt3GradleSubplugin
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
@@ -53,15 +52,15 @@ class PasswordStorePlugin : Plugin<Project> {
project.extensions.getByType<BaseAppModuleExtension>().configureBuildSigning(project)
project.extensions.getByType<TestedExtension>().configureCommonAndroidOptions()
}
- is SpotlessPlugin -> {
- project.extensions.getByType<SpotlessExtension>().configureSpotless()
- }
is SigningPlugin -> {
project.extensions.getByType<SigningExtension>().configureBuildSigning()
}
is KotlinPluginWrapper -> {
project.configureExplicitApi()
}
+ is Kapt3GradleSubplugin -> {
+ project.configureKapt()
+ }
}
}
}
diff --git a/buildSrc/src/main/java/Spotless.kt b/buildSrc/src/main/java/Spotless.kt
index 859faf73..bab6f58d 100644
--- a/buildSrc/src/main/java/Spotless.kt
+++ b/buildSrc/src/main/java/Spotless.kt
@@ -4,16 +4,28 @@
*/
import com.diffplug.gradle.spotless.SpotlessExtension
+import org.gradle.api.Project
+import org.gradle.kotlin.dsl.apply
+import org.gradle.kotlin.dsl.configure
-internal fun SpotlessExtension.configureSpotless() {
- kotlin {
- ktfmt().googleStyle()
- target("src/**/*.kt", "**/*.kts")
- }
- format("xml") {
- target("**/*.xml")
- trimTrailingWhitespace()
- indentWithSpaces()
- endWithNewline()
+fun Project.configureSpotless() {
+ apply(plugin = "com.diffplug.spotless")
+ configure<SpotlessExtension> {
+ kotlin {
+ ktfmt().googleStyle()
+ target("**/*.kt")
+ targetExclude("**/build/")
+ }
+ kotlinGradle {
+ ktfmt().googleStyle()
+ target("**/*.kts")
+ }
+ format("xml") {
+ target("**/*.xml")
+ targetExclude("**/build/", ".idea/")
+ trimTrailingWhitespace()
+ indentWithSpaces()
+ endWithNewline()
+ }
}
}