mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-17 23:47:02 +05:30
all: reformat with ktfmt google style
Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
8448910628
commit
db07a12be5
54 changed files with 496 additions and 656 deletions
|
@ -18,14 +18,12 @@ 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.
|
||||
* 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<Delete>("clean") {
|
||||
delete(rootProject.buildDir)
|
||||
}
|
||||
tasks.register<Delete>("clean") { delete(rootProject.buildDir) }
|
||||
tasks.withType<Wrapper> {
|
||||
gradleVersion = "7.0-rc-1"
|
||||
distributionType = Wrapper.DistributionType.ALL
|
||||
|
@ -33,18 +31,12 @@ internal fun Project.configureForRootProject() {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure all projects including the root project
|
||||
*/
|
||||
/** Configure all projects including the root project */
|
||||
internal fun Project.configureForAllProjects() {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
jcenter {
|
||||
content {
|
||||
includeGroup("org.jetbrains.compose.*")
|
||||
}
|
||||
}
|
||||
jcenter { content { includeGroup("org.jetbrains.compose.*") } }
|
||||
maven("https://dl.bintray.com/kotlin/kotlinx") {
|
||||
name = "KotlinX Bintray"
|
||||
content {
|
||||
|
@ -62,25 +54,23 @@ internal fun Project.configureForAllProjects() {
|
|||
}
|
||||
tasks.withType<Test> {
|
||||
maxParallelForks = Runtime.getRuntime().availableProcessors() * 2
|
||||
testLogging {
|
||||
events(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED)
|
||||
}
|
||||
testLogging { events(TestLogEvent.PASSED, TestLogEvent.SKIPPED, TestLogEvent.FAILED) }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply configuration options for Android Application projects.
|
||||
*/
|
||||
/** Apply configuration options for Android Application projects. */
|
||||
@Suppress("UnstableApiUsage")
|
||||
internal fun BaseAppModuleExtension.configureAndroidApplicationOptions(project: Project) {
|
||||
val minifySwitch =
|
||||
project.providers.environmentVariable("DISABLE_MINIFY").forUseAtConfigurationTime()
|
||||
project.tasks.withType<KotlinCompile> {
|
||||
kotlinOptions {
|
||||
freeCompilerArgs = freeCompilerArgs + listOf(
|
||||
"-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
|
||||
"-Xopt-in=androidx.compose.material.ExperimentalMaterialApi"
|
||||
)
|
||||
freeCompilerArgs =
|
||||
freeCompilerArgs +
|
||||
listOf(
|
||||
"-Xopt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
|
||||
"-Xopt-in=androidx.compose.material.ExperimentalMaterialApi"
|
||||
)
|
||||
}
|
||||
}
|
||||
adbOptions.installOptions("--user 0")
|
||||
|
@ -97,9 +87,7 @@ internal fun BaseAppModuleExtension.configureAndroidApplicationOptions(project:
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply baseline configurations for all Android projects (Application and Library).
|
||||
*/
|
||||
/** Apply baseline configurations for all Android projects (Application and Library). */
|
||||
@Suppress("UnstableApiUsage")
|
||||
internal fun TestedExtension.configureCommonAndroidOptions() {
|
||||
compileSdkVersion(30)
|
||||
|
|
|
@ -9,7 +9,8 @@ import org.gradle.kotlin.dsl.withType
|
|||
/**
|
||||
* A plugin that enables Java 8 desugaring for consuming new Java language APIs.
|
||||
*
|
||||
* Apply this plugin to the build.gradle.kts file in Android Application or Android Library projects:
|
||||
* Apply this plugin to the build.gradle.kts file in Android Application or Android Library
|
||||
* projects:
|
||||
* ```
|
||||
* plugins {
|
||||
* `core-library-desugaring`
|
||||
|
|
|
@ -2,9 +2,7 @@ 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].
|
||||
*/
|
||||
/** Apply default kapt configs to the [Project]. */
|
||||
internal fun Project.configureKapt() {
|
||||
extensions.configure<KaptExtension> {
|
||||
javacOptions {
|
||||
|
@ -17,15 +15,14 @@ internal fun Project.configureKapt() {
|
|||
}
|
||||
}
|
||||
// disable kapt tasks for unit tests
|
||||
tasks.matching {
|
||||
it.name.startsWith("kapt") && it.name.endsWith("UnitTestKotlin")
|
||||
}.configureEach { enabled = false }
|
||||
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 == "dagger-compiler"
|
||||
get() =
|
||||
configurations.any {
|
||||
it.dependencies.any { dependency -> dependency.name == "dagger-compiler" }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,5 @@
|
|||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*/
|
||||
|
||||
internal val additionalCompilerArgs = listOf(
|
||||
"-Xopt-in=kotlin.RequiresOptIn",
|
||||
"-Xskip-prerelease-check"
|
||||
)
|
||||
internal val additionalCompilerArgs =
|
||||
listOf("-Xopt-in=kotlin.RequiresOptIn", "-Xskip-prerelease-check")
|
||||
|
|
|
@ -29,8 +29,7 @@ class LobstersPlugin : Plugin<Project> {
|
|||
|
||||
project.plugins.all {
|
||||
when (this) {
|
||||
is JavaPlugin,
|
||||
is JavaLibraryPlugin -> {
|
||||
is JavaPlugin, is JavaLibraryPlugin -> {
|
||||
project.tasks.withType<JavaCompile> {
|
||||
options.compilerArgs.add("-Xlint:unchecked")
|
||||
options.isDeprecation = true
|
||||
|
@ -42,7 +41,9 @@ class LobstersPlugin : Plugin<Project> {
|
|||
is AppPlugin -> {
|
||||
project.extensions.getByType<TestedExtension>().configureCommonAndroidOptions()
|
||||
project.extensions.getByType<BaseAppModuleExtension>().configureBuildSigning(project)
|
||||
project.extensions.getByType<BaseAppModuleExtension>()
|
||||
project
|
||||
.extensions
|
||||
.getByType<BaseAppModuleExtension>()
|
||||
.configureAndroidApplicationOptions(project)
|
||||
}
|
||||
is Kapt3GradleSubplugin -> {
|
||||
|
@ -56,4 +57,5 @@ class LobstersPlugin : Plugin<Project> {
|
|||
}
|
||||
}
|
||||
|
||||
private val Project.isRoot get() = this == this.rootProject
|
||||
private val Project.isRoot
|
||||
get() = this == this.rootProject
|
||||
|
|
|
@ -9,9 +9,7 @@ import org.gradle.api.Project
|
|||
|
||||
private const val KEYSTORE_CONFIG_PATH = "keystore.properties"
|
||||
|
||||
/**
|
||||
* Configure signing for all build types.
|
||||
*/
|
||||
/** Configure signing for all build types. */
|
||||
@Suppress("UnstableApiUsage")
|
||||
internal fun BaseAppModuleExtension.configureBuildSigning(project: Project) {
|
||||
with(project) {
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
* SPDX-License-Identifier: GPL-3.0-only
|
||||
*/
|
||||
|
||||
|
||||
import com.android.build.gradle.internal.plugins.AppPlugin
|
||||
import com.github.zafarkhaja.semver.Version
|
||||
import java.io.OutputStream
|
||||
|
@ -14,34 +13,26 @@ import org.gradle.api.Project
|
|||
private const val VERSIONING_PROP_FILE = "version.properties"
|
||||
private const val VERSIONING_PROP_VERSION_NAME = "versioning-plugin.versionName"
|
||||
private const val VERSIONING_PROP_VERSION_CODE = "versioning-plugin.versionCode"
|
||||
private const val VERSIONING_PROP_COMMENT = """
|
||||
private const val VERSIONING_PROP_COMMENT =
|
||||
"""
|
||||
This file was automatically generated by 'versioning-plugin'. DO NOT EDIT MANUALLY.
|
||||
"""
|
||||
|
||||
/**
|
||||
* A Gradle [Plugin] that takes a [Project] with the [AppPlugin] applied and dynamically sets the
|
||||
* versionCode and versionName properties based on values read from a [VERSIONING_PROP_FILE] file in
|
||||
* the [Project.getBuildDir] directory. It also adds Gradle tasks to bump the major, minor, and patch
|
||||
* versions along with one to prepare the next snapshot.
|
||||
* the [Project.getBuildDir] directory. It also adds Gradle tasks to bump the major, minor, and
|
||||
* patch versions along with one to prepare the next snapshot.
|
||||
*/
|
||||
@Suppress(
|
||||
"UnstableApiUsage",
|
||||
"NAME_SHADOWING"
|
||||
)
|
||||
@Suppress("UnstableApiUsage", "NAME_SHADOWING")
|
||||
class VersioningPlugin : Plugin<Project> {
|
||||
|
||||
/**
|
||||
* Generate the Android 'versionCode' property
|
||||
*/
|
||||
/** Generate the Android 'versionCode' property */
|
||||
private fun Version.androidCode(): Int {
|
||||
return majorVersion * 1_00_00 +
|
||||
minorVersion * 1_00 +
|
||||
patchVersion
|
||||
return majorVersion * 1_00_00 + minorVersion * 1_00 + patchVersion
|
||||
}
|
||||
|
||||
/**
|
||||
* Write an Android-specific variant of [this] to [stream]
|
||||
*/
|
||||
/** Write an Android-specific variant of [this] to [stream] */
|
||||
private fun Version.writeForAndroid(stream: OutputStream) {
|
||||
val newVersionCode = androidCode()
|
||||
val props = Properties()
|
||||
|
@ -50,27 +41,27 @@ class VersioningPlugin : Plugin<Project> {
|
|||
props.store(stream, VERSIONING_PROP_COMMENT)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the same [Version], but with build metadata stripped.
|
||||
*/
|
||||
/** Returns the same [Version], but with build metadata stripped. */
|
||||
private fun Version.clearPreRelease(): Version {
|
||||
return Version.forIntegers(majorVersion, minorVersion, patchVersion)
|
||||
}
|
||||
|
||||
override fun apply(project: Project) {
|
||||
with(project) {
|
||||
val appPlugin = requireNotNull(plugins.findPlugin(AppPlugin::class.java)) {
|
||||
"Plugin 'com.android.application' must be applied to use this plugin"
|
||||
}
|
||||
val appPlugin =
|
||||
requireNotNull(plugins.findPlugin(AppPlugin::class.java)) {
|
||||
"Plugin 'com.android.application' must be applied to use this plugin"
|
||||
}
|
||||
val propFile = layout.projectDirectory.file(VERSIONING_PROP_FILE)
|
||||
require(propFile.asFile.exists()) {
|
||||
"A 'version.properties' file must exist in the project subdirectory to use this plugin"
|
||||
}
|
||||
val contents = providers.fileContents(propFile).asText.forUseAtConfigurationTime()
|
||||
val versionProps = Properties().also { it.load(contents.get().byteInputStream()) }
|
||||
val versionName = requireNotNull(versionProps.getProperty(VERSIONING_PROP_VERSION_NAME)) {
|
||||
"version.properties must contain a '$VERSIONING_PROP_VERSION_NAME' property"
|
||||
}
|
||||
val versionName =
|
||||
requireNotNull(versionProps.getProperty(VERSIONING_PROP_VERSION_NAME)) {
|
||||
"version.properties must contain a '$VERSIONING_PROP_VERSION_NAME' property"
|
||||
}
|
||||
val versionCode =
|
||||
requireNotNull(versionProps.getProperty(VERSIONING_PROP_VERSION_CODE).toInt()) {
|
||||
"version.properties must contain a '$VERSIONING_PROP_VERSION_CODE' property"
|
||||
|
@ -80,32 +71,21 @@ class VersioningPlugin : Plugin<Project> {
|
|||
afterEvaluate {
|
||||
val version = Version.valueOf(versionName)
|
||||
tasks.register("clearPreRelease") {
|
||||
doLast {
|
||||
version.clearPreRelease()
|
||||
.writeForAndroid(propFile.asFile.outputStream())
|
||||
}
|
||||
doLast { version.clearPreRelease().writeForAndroid(propFile.asFile.outputStream()) }
|
||||
}
|
||||
tasks.register("bumpMajor") {
|
||||
doLast {
|
||||
version.incrementMajorVersion()
|
||||
.writeForAndroid(propFile.asFile.outputStream())
|
||||
}
|
||||
doLast { version.incrementMajorVersion().writeForAndroid(propFile.asFile.outputStream()) }
|
||||
}
|
||||
tasks.register("bumpMinor") {
|
||||
doLast {
|
||||
version.incrementMinorVersion()
|
||||
.writeForAndroid(propFile.asFile.outputStream())
|
||||
}
|
||||
doLast { version.incrementMinorVersion().writeForAndroid(propFile.asFile.outputStream()) }
|
||||
}
|
||||
tasks.register("bumpPatch") {
|
||||
doLast {
|
||||
version.incrementPatchVersion()
|
||||
.writeForAndroid(propFile.asFile.outputStream())
|
||||
}
|
||||
doLast { version.incrementPatchVersion().writeForAndroid(propFile.asFile.outputStream()) }
|
||||
}
|
||||
tasks.register("bumpSnapshot") {
|
||||
doLast {
|
||||
version.incrementMinorVersion()
|
||||
version
|
||||
.incrementMinorVersion()
|
||||
.setPreReleaseVersion("SNAPSHOT")
|
||||
.writeForAndroid(propFile.asFile.outputStream())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue