mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 15:17:05 +05:30
build-logic: rewrite everything to use full Gradle plugins
This commit is contained in:
parent
49863d4138
commit
29d63a879e
29 changed files with 415 additions and 301 deletions
|
@ -17,7 +17,35 @@ afterEvaluate {
|
|||
}
|
||||
|
||||
tasks.withType<KotlinCompile>().configureEach {
|
||||
kotlinOptions { jvmTarget = JavaVersion.VERSION_11.toString() }
|
||||
kotlinOptions {
|
||||
jvmTarget = JavaVersion.VERSION_11.toString()
|
||||
freeCompilerArgs = freeCompilerArgs + "-Xsam-conversions=class"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gradlePlugin {
|
||||
plugins {
|
||||
register("kotlin-android") {
|
||||
id = "dev.msfjarvis.claw.kotlin-android"
|
||||
implementationClass = "dev.msfjarvis.aps.gradle.KotlinAndroidPlugin"
|
||||
}
|
||||
register("kotlin-common") {
|
||||
id = "dev.msfjarvis.claw.kotlin-common"
|
||||
implementationClass = "dev.msfjarvis.aps.gradle.KotlinCommonPlugin"
|
||||
}
|
||||
register("kotlin-kapt") {
|
||||
id = "dev.msfjarvis.claw.kotlin-kapt"
|
||||
implementationClass = "dev.msfjarvis.aps.gradle.KotlinKaptPlugin"
|
||||
}
|
||||
register("kotlin-library") {
|
||||
id = "dev.msfjarvis.claw.kotlin-library"
|
||||
implementationClass = "dev.msfjarvis.aps.gradle.KotlinLibraryPlugin"
|
||||
}
|
||||
register("spotless") {
|
||||
id = "dev.msfjarvis.claw.spotless"
|
||||
implementationClass = "dev.msfjarvis.aps.gradle.SpotlessPlugin"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,6 +54,4 @@ dependencies {
|
|||
implementation(libs.build.kotlin.gradle)
|
||||
implementation(libs.build.kotlin.serialization)
|
||||
implementation(libs.build.spotless)
|
||||
implementation(libs.build.vcu)
|
||||
implementation(libs.build.versions)
|
||||
}
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
/*
|
||||
* Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*/
|
||||
|
||||
plugins {
|
||||
kotlin("android")
|
||||
id("dev.msfjarvis.claw.kotlin-common")
|
||||
}
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
* Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*/
|
||||
|
||||
import org.gradle.api.JavaVersion
|
||||
import org.gradle.api.tasks.compile.JavaCompile
|
||||
import org.gradle.api.tasks.testing.Test
|
||||
import org.gradle.api.tasks.testing.logging.TestLogEvent
|
||||
import org.gradle.kotlin.dsl.withType
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
val additionalCompilerArgs =
|
||||
listOf(
|
||||
"-Xopt-in=kotlin.RequiresOptIn",
|
||||
"-P",
|
||||
"plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=true",
|
||||
)
|
||||
|
||||
tasks.withType<JavaCompile>().configureEach {
|
||||
sourceCompatibility = JavaVersion.VERSION_11.toString()
|
||||
targetCompatibility = JavaVersion.VERSION_11.toString()
|
||||
}
|
||||
|
||||
tasks.withType<KotlinCompile>().configureEach {
|
||||
kotlinOptions {
|
||||
// TODO: Re-enable once warnings from Aurora-generated code are fixed
|
||||
allWarningsAsErrors = false
|
||||
jvmTarget = JavaVersion.VERSION_11.toString()
|
||||
freeCompilerArgs = freeCompilerArgs + additionalCompilerArgs
|
||||
languageVersion = "1.5"
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType<Test>().configureEach {
|
||||
maxParallelForks = Runtime.getRuntime().availableProcessors() * 2
|
||||
testLogging { events(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED) }
|
||||
doNotTrackState("We want tests to always run even if Gradle thinks otherwise")
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
/*
|
||||
* Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*/
|
||||
|
||||
import org.gradle.api.Project
|
||||
|
||||
plugins {
|
||||
kotlin("android")
|
||||
kotlin("kapt")
|
||||
}
|
||||
|
||||
afterEvaluate {
|
||||
kapt {
|
||||
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 }
|
||||
|
||||
fun Project.hasDaggerCompilerDependency(): Boolean {
|
||||
return configurations.any {
|
||||
it.dependencies.any { dependency -> dependency.name == "hilt-compiler" }
|
||||
}
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
/*
|
||||
* Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*/
|
||||
|
||||
plugins { id("dev.msfjarvis.claw.kotlin-common") }
|
|
@ -1,28 +0,0 @@
|
|||
/*
|
||||
* Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*/
|
||||
|
||||
plugins { id("com.diffplug.spotless") }
|
||||
|
||||
val KTFMT_VERSION = "0.37"
|
||||
|
||||
spotless {
|
||||
kotlin {
|
||||
ktfmt(KTFMT_VERSION).googleStyle()
|
||||
target("**/*.kt")
|
||||
targetExclude("**/build/", "**/gen/")
|
||||
}
|
||||
kotlinGradle {
|
||||
ktfmt(KTFMT_VERSION).googleStyle()
|
||||
target("**/*.kts")
|
||||
targetExclude("**/build/")
|
||||
}
|
||||
format("xml") {
|
||||
target("**/*.xml")
|
||||
targetExclude("**/build/", ".idea/")
|
||||
trimTrailingWhitespace()
|
||||
indentWithSpaces()
|
||||
endWithNewline()
|
||||
}
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
|
||||
|
||||
plugins {
|
||||
id("com.github.ben-manes.versions")
|
||||
id("nl.littlerobots.version-catalog-update")
|
||||
}
|
||||
|
||||
versionCatalogUpdate {
|
||||
keep {
|
||||
// This clears out build-logic specific dependencies
|
||||
keepUnusedLibraries.set(true)
|
||||
}
|
||||
}
|
||||
|
||||
fun isNonStable(version: String): Boolean {
|
||||
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.toUpperCase().contains(it) }
|
||||
val regex = "^[0-9,.v-]+(-r)?$".toRegex()
|
||||
val isStable = stableKeyword || regex.matches(version)
|
||||
return isStable.not()
|
||||
}
|
||||
|
||||
tasks.withType<DependencyUpdatesTask>().configureEach {
|
||||
rejectVersionIf {
|
||||
when (candidate.group) {
|
||||
"com.android.application",
|
||||
"com.android.library",
|
||||
"com.google.accompanist",
|
||||
"org.jetbrains.kotlin" -> true
|
||||
else -> isNonStable(candidate.version) && !isNonStable(currentVersion)
|
||||
}
|
||||
}
|
||||
checkForGradleUpdate = false
|
||||
checkBuildEnvironmentConstraints = true
|
||||
outputFormatter = "json"
|
||||
outputDir = "build/dependencyUpdates"
|
||||
reportfileName = "report"
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*/
|
||||
|
||||
package dev.msfjarvis.aps.gradle
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.apply
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinAndroidPluginWrapper
|
||||
|
||||
@Suppress("Unused")
|
||||
class KotlinAndroidPlugin : Plugin<Project> {
|
||||
|
||||
override fun apply(project: Project) {
|
||||
project.pluginManager.run {
|
||||
apply(KotlinAndroidPluginWrapper::class)
|
||||
apply(KotlinCommonPlugin::class)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*/
|
||||
|
||||
package dev.msfjarvis.aps.gradle
|
||||
|
||||
import org.gradle.api.JavaVersion
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.tasks.compile.JavaCompile
|
||||
import org.gradle.api.tasks.testing.Test
|
||||
import org.gradle.api.tasks.testing.logging.TestLogEvent
|
||||
import org.gradle.kotlin.dsl.withType
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
@Suppress("Unused")
|
||||
class KotlinCommonPlugin : Plugin<Project> {
|
||||
|
||||
override fun apply(project: Project) {
|
||||
project.tasks.run {
|
||||
withType<JavaCompile>().configureEach {
|
||||
sourceCompatibility = JavaVersion.VERSION_11.toString()
|
||||
targetCompatibility = JavaVersion.VERSION_11.toString()
|
||||
}
|
||||
withType<KotlinCompile>().configureEach {
|
||||
kotlinOptions {
|
||||
allWarningsAsErrors = false
|
||||
jvmTarget = JavaVersion.VERSION_11.toString()
|
||||
freeCompilerArgs = freeCompilerArgs + ADDITIONAL_COMPILER_ARGS
|
||||
languageVersion = "1.5"
|
||||
}
|
||||
}
|
||||
withType<Test>().configureEach {
|
||||
maxParallelForks = Runtime.getRuntime().availableProcessors() * 2
|
||||
testLogging { events(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED) }
|
||||
doNotTrackState("We want tests to always run even if Gradle thinks otherwise")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
private val ADDITIONAL_COMPILER_ARGS =
|
||||
listOf(
|
||||
"-opt-in=kotlin.RequiresOptIn",
|
||||
"-P",
|
||||
"plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=true",
|
||||
)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*/
|
||||
|
||||
package dev.msfjarvis.aps.gradle
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.apply
|
||||
import org.gradle.kotlin.dsl.getByType
|
||||
import org.jetbrains.kotlin.gradle.internal.Kapt3GradleSubplugin
|
||||
import org.jetbrains.kotlin.gradle.plugin.KaptExtension
|
||||
import org.jetbrains.kotlin.gradle.plugin.KotlinAndroidPluginWrapper
|
||||
|
||||
@Suppress("Unused")
|
||||
class KotlinKaptPlugin : Plugin<Project> {
|
||||
|
||||
override fun apply(project: Project) {
|
||||
project.pluginManager.run {
|
||||
apply(KotlinAndroidPluginWrapper::class)
|
||||
apply(Kapt3GradleSubplugin::class)
|
||||
}
|
||||
project.afterEvaluate {
|
||||
project.extensions.getByType<KaptExtension>().run {
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
project.tasks
|
||||
.matching { it.name.startsWith("kapt") && it.name.endsWith("UnitTestKotlin") }
|
||||
.configureEach { enabled = false }
|
||||
}
|
||||
|
||||
private fun Project.hasDaggerCompilerDependency(): Boolean {
|
||||
return configurations.any {
|
||||
it.dependencies.any { dependency -> dependency.name == "hilt-compiler" }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
* Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*/
|
||||
|
||||
package dev.msfjarvis.aps.gradle
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.kotlin.dsl.apply
|
||||
|
||||
@Suppress("Unused")
|
||||
class KotlinLibraryPlugin : Plugin<Project> {
|
||||
|
||||
override fun apply(project: Project) {
|
||||
project.pluginManager.apply(KotlinCommonPlugin::class)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright © 2014-2021 The Android Password Store Authors. All Rights Reserved.
|
||||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*/
|
||||
|
||||
package dev.msfjarvis.aps.gradle
|
||||
|
||||
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.kotlin.dsl.apply
|
||||
import org.gradle.kotlin.dsl.getByType
|
||||
|
||||
@Suppress("Unused")
|
||||
class SpotlessPlugin : Plugin<Project> {
|
||||
|
||||
override fun apply(project: Project) {
|
||||
project.pluginManager.apply(SpotlessPlugin::class)
|
||||
project.extensions.getByType<SpotlessExtension>().run {
|
||||
kotlin {
|
||||
ktfmt(KTFMT_VERSION).googleStyle()
|
||||
target("**/*.kt")
|
||||
targetExclude("**/build/", "**/gen/")
|
||||
}
|
||||
kotlinGradle {
|
||||
ktfmt(KTFMT_VERSION).googleStyle()
|
||||
target("**/*.kts")
|
||||
targetExclude("**/build/")
|
||||
}
|
||||
format("xml") {
|
||||
target("**/*.xml")
|
||||
targetExclude("**/build/", ".idea/")
|
||||
trimTrailingWhitespace()
|
||||
indentWithSpaces()
|
||||
endWithNewline()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
private const val KTFMT_VERSION = "0.38"
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue