Configure Spotless for all projects and tweak Dagger flags (#1427)

This commit is contained in:
Harsh Shandilya 2021-06-01 15:05:05 +05:30 committed by GitHub
parent f769968bdc
commit 3ae105df92
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 61 additions and 16 deletions

View file

@ -7,4 +7,4 @@ plugins {
`aps-plugin` `aps-plugin`
} }
allprojects { apply(plugin = "com.diffplug.spotless") } allprojects { configureSpotless() }

View file

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

View file

@ -7,8 +7,6 @@ import com.android.build.gradle.TestedExtension
import com.android.build.gradle.internal.dsl.BaseAppModuleExtension import com.android.build.gradle.internal.dsl.BaseAppModuleExtension
import com.android.build.gradle.internal.plugins.AppPlugin import com.android.build.gradle.internal.plugins.AppPlugin
import com.android.build.gradle.internal.plugins.LibraryPlugin 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.Plugin
import org.gradle.api.Project import org.gradle.api.Project
import org.gradle.api.plugins.JavaLibraryPlugin 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.SigningExtension
import org.gradle.plugins.signing.SigningPlugin import org.gradle.plugins.signing.SigningPlugin
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension 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.plugin.KotlinPluginWrapper
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
@ -53,15 +52,15 @@ class PasswordStorePlugin : Plugin<Project> {
project.extensions.getByType<BaseAppModuleExtension>().configureBuildSigning(project) project.extensions.getByType<BaseAppModuleExtension>().configureBuildSigning(project)
project.extensions.getByType<TestedExtension>().configureCommonAndroidOptions() project.extensions.getByType<TestedExtension>().configureCommonAndroidOptions()
} }
is SpotlessPlugin -> {
project.extensions.getByType<SpotlessExtension>().configureSpotless()
}
is SigningPlugin -> { is SigningPlugin -> {
project.extensions.getByType<SigningExtension>().configureBuildSigning() project.extensions.getByType<SigningExtension>().configureBuildSigning()
} }
is KotlinPluginWrapper -> { is KotlinPluginWrapper -> {
project.configureExplicitApi() project.configureExplicitApi()
} }
is Kapt3GradleSubplugin -> {
project.configureKapt()
}
} }
} }
} }

View file

@ -4,16 +4,28 @@
*/ */
import com.diffplug.gradle.spotless.SpotlessExtension 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() { fun Project.configureSpotless() {
kotlin { apply(plugin = "com.diffplug.spotless")
ktfmt().googleStyle() configure<SpotlessExtension> {
target("src/**/*.kt", "**/*.kts") kotlin {
} ktfmt().googleStyle()
format("xml") { target("**/*.kt")
target("**/*.xml") targetExclude("**/build/")
trimTrailingWhitespace() }
indentWithSpaces() kotlinGradle {
endWithNewline() ktfmt().googleStyle()
target("**/*.kts")
}
format("xml") {
target("**/*.xml")
targetExclude("**/build/", ".idea/")
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
}
} }
} }