diff --git a/.editorconfig b/.editorconfig index eba4c9f..933ee57 100644 --- a/.editorconfig +++ b/.editorconfig @@ -22,14 +22,15 @@ root = true [*] +indent_size = 4 +end_of_line = lf charset = utf-8 indent_style = space insert_final_newline = true trim_trailing_whitespace = true +max_line_length = 120 [*.{kt,kts}] -indent_size = 4 -end_of_line = lf ij_kotlin_allow_trailing_comma = false ktlint_standard = enabled ktlint_experimental = enabled @@ -38,6 +39,7 @@ ktlint_standard_no-unused-imports = enabled ktlint_standard_no-unit-return = enabled ktlint_function_signature_body_expression_wrapping = multiline ktlint_standard_no-consecutive-blank-lines = enabled +ktlint_standard_no-unused-imports = enabled ktlint_experimental_fun-keyword-spacing = enabled ktlint_experimental_unnecessary-parentheses-before-trailing-lambda = enabled ktlint_experimental_property-naming = disabled @@ -46,6 +48,5 @@ ktlint_standard_annotation-spacing = disabled ktlint_standard_filename = disabled ktlint_standard_no-wildcard-imports = disabled ktlint_standard_argument-list-wrapping = disabled - -[*.{json,yaml,yml,md}] -indent_size = 2 +ktlint_standard_import-ordering = disabled +max_line_length = off diff --git a/assets/HEADING b/assets/HEADING index 5e15766..bb7f395 100755 --- a/assets/HEADING +++ b/assets/HEADING @@ -1,6 +1,6 @@ /* - * 🤹 common-utils: Common Kotlin utilities made for my personal usage. - * Copyright (c) 2021-2023 Noel + * 🤹 common-utils: Common Java and Kotlin utilities for Noel's projects ^w^ + * Copyright (c) 2021-2023 Noel Towa * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/bom/build.gradle.kts b/bom/build.gradle.kts index 22aba41..2f9fa51 100644 --- a/bom/build.gradle.kts +++ b/bom/build.gradle.kts @@ -1,6 +1,6 @@ /* - * 🤹 common-utils: Common Kotlin utilities made for my personal usage. - * Copyright (c) 2021-2023 Noel + * 🤹 common-utils: Common Java and Kotlin utilities for Noel's projects ^w^ + * Copyright (c) 2021-2023 Noel Towa * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/build.gradle.kts b/build.gradle.kts index 840cd25..79aeb97 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,6 @@ /* - * 🤹 common-utils: Common Kotlin utilities made for my personal usage. - * Copyright (c) 2021-2023 Noel + * 🤹 common-utils: Common Java and Kotlin utilities for Noel's projects ^w^ + * Copyright (c) 2021-2023 Noel Towa * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -41,6 +41,22 @@ repositories { mavenLocal() } +spotless { + // For Kotlin (Gradle), we will need to move the license header + // as the last step due to https://github.com/diffplug/spotless/issues/1599 + kotlinGradle { + endWithNewline() + encoding("UTF-8") + target("**/*.gradle.kts") + ktlint().apply { + setUseExperimental(true) + setEditorConfigPath(file("${rootProject.projectDir}/.editorconfig")) + } + + licenseHeaderFile(file("${rootProject.projectDir}/assets/HEADING"), "(package |@file|import |pluginManagement|plugins|rootProject.name)") + } +} + tasks { wrapper { distributionType = ALL diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 2e47f64..a1989ca 100755 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -1,6 +1,6 @@ /* - * 🤹 common-utils: Common Kotlin utilities made for my personal usage. - * Copyright (c) 2021-2023 Noel + * 🤹 common-utils: Common Java and Kotlin utilities for Noel's projects ^w^ + * Copyright (c) 2021-2023 Noel Towa * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -22,11 +22,10 @@ */ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -import org.gradle.api.JavaVersion plugins { + id("com.diffplug.spotless") version "6.17.0" `kotlin-dsl` - groovy } repositories { @@ -42,6 +41,59 @@ dependencies { implementation(gradleApi()) } -tasks.withType().configureEach { - kotlinOptions.jvmTarget = JavaVersion.VERSION_17.toString() +kotlin { + jvmToolchain { + languageVersion.set(JavaLanguageVersion.of(17)) + } +} + +spotless { + // For Kotlin and Kotlin (Gradle), we will need to move the license header + // as the last step due to https://github.com/diffplug/spotless/issues/1599 + kotlin { + endWithNewline() + encoding("UTF-8") + target("**/*.kt") + ktlint().apply { + setUseExperimental(true) + setEditorConfigPath(file("${rootProject.projectDir}/../.editorconfig")) + } + + licenseHeaderFile(file("${rootProject.projectDir}/../assets/HEADING")) + } + + kotlinGradle { + endWithNewline() + encoding("UTF-8") + target("**/*.gradle.kts") + ktlint().apply { + setUseExperimental(true) + setEditorConfigPath(file("${rootProject.projectDir}/../.editorconfig")) + } + + licenseHeaderFile(file("${rootProject.projectDir}/../assets/HEADING"), "(package |@file|import |pluginManagement|plugins|rootProject.name)") + } + + java { + licenseHeaderFile(file("${rootProject.projectDir}/../assets/HEADING")) + trimTrailingWhitespace() + removeUnusedImports() + palantirJavaFormat() + endWithNewline() + encoding("UTF-8") + } +} + +tasks { + withType().configureEach { + kotlinOptions.jvmTarget = "17" + } +} + +configurations.configureEach { + if (isCanBeResolved) { + attributes { + attribute(GradlePluginApiVersion.GRADLE_PLUGIN_API_VERSION_ATTRIBUTE, project.objects.named(GradleVersion.current().version)) + } + } } diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts new file mode 100644 index 0000000..1a1b4ee --- /dev/null +++ b/buildSrc/settings.gradle.kts @@ -0,0 +1,42 @@ +/* + * 🤹 common-utils: Common Java and Kotlin utilities for Noel's projects ^w^ + * Copyright (c) 2021-2023 Noel Towa + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +import org.gradle.toolchains.foojay.FoojayToolchainsConventionPlugin + +pluginManagement { + repositories { + gradlePluginPortal() + } +} + +buildscript { + repositories { + gradlePluginPortal() + } + + dependencies { + classpath("org.gradle.toolchains:foojay-resolver:0.4.0") + } +} + +apply() diff --git a/buildSrc/src/main/kotlin/commons-module.gradle.kts b/buildSrc/src/main/kotlin/commons-module.gradle.kts index 6980dff..84e4ce6 100644 --- a/buildSrc/src/main/kotlin/commons-module.gradle.kts +++ b/buildSrc/src/main/kotlin/commons-module.gradle.kts @@ -1,6 +1,6 @@ /* - * 🤹 common-utils: Common Kotlin utilities made for my personal usage. - * Copyright (c) 2021-2023 Noel + * 🤹 common-utils: Common Java and Kotlin utilities for Noel's projects ^w^ + * Copyright (c) 2021-2023 Noel Towa * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/buildSrc/src/main/kotlin/dev/floofy/utils/gradle/Metadata.kt b/buildSrc/src/main/kotlin/dev/floofy/utils/gradle/Metadata.kt index 4e60340..c35b649 100644 --- a/buildSrc/src/main/kotlin/dev/floofy/utils/gradle/Metadata.kt +++ b/buildSrc/src/main/kotlin/dev/floofy/utils/gradle/Metadata.kt @@ -28,7 +28,7 @@ import org.gradle.api.JavaVersion /** * Returns the current version of `commons-utils` package. */ -val VERSION = "2.5.0" +val VERSION = "2.5.1" /** * The Java version it's being compiled to. diff --git a/extensions-koin/build.gradle.kts b/extensions-koin/build.gradle.kts index 812aa69..c26672a 100644 --- a/extensions-koin/build.gradle.kts +++ b/extensions-koin/build.gradle.kts @@ -1,6 +1,6 @@ /* - * 🤹 common-utils: Common Kotlin utilities made for my personal usage. - * Copyright (c) 2021-2023 Noel + * 🤹 common-utils: Common Java and Kotlin utilities for Noel's projects ^w^ + * Copyright (c) 2021-2023 Noel Towa * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/extensions-kotlin/build.gradle.kts b/extensions-kotlin/build.gradle.kts index c92dc4a..62ec92c 100644 --- a/extensions-kotlin/build.gradle.kts +++ b/extensions-kotlin/build.gradle.kts @@ -1,6 +1,6 @@ /* - * 🤹 common-utils: Common Kotlin utilities made for my personal usage. - * Copyright (c) 2021-2023 Noel + * 🤹 common-utils: Common Java and Kotlin utilities for Noel's projects ^w^ + * Copyright (c) 2021-2023 Noel Towa * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/gradle-utils/build.gradle.kts b/gradle-utils/build.gradle.kts index b7b04a3..63eef9c 100644 --- a/gradle-utils/build.gradle.kts +++ b/gradle-utils/build.gradle.kts @@ -1,6 +1,6 @@ /* - * 🤹 common-utils: Common Kotlin utilities made for my personal usage. - * Copyright (c) 2021-2023 Noel + * 🤹 common-utils: Common Java and Kotlin utilities for Noel's projects ^w^ + * Copyright (c) 2021-2023 Noel Towa * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/gradle-utils/src/test/java/dev/floofy/utils/gradle/tests/GradleExtensionsTest.java b/gradle-utils/src/test/java/dev/floofy/utils/gradle/tests/GradleExtensionsTest.java index 01f4715..c6f138c 100644 --- a/gradle-utils/src/test/java/dev/floofy/utils/gradle/tests/GradleExtensionsTest.java +++ b/gradle-utils/src/test/java/dev/floofy/utils/gradle/tests/GradleExtensionsTest.java @@ -1,6 +1,6 @@ /* - * 🤹 common-utils: Common Kotlin utilities made for my personal usage. - * Copyright (c) 2021-2023 Noel + * 🤹 common-utils: Common Java and Kotlin utilities for Noel's projects ^w^ + * Copyright (c) 2021-2023 Noel Towa * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/gradle.properties b/gradle.properties index 9817fd4..a748451 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,9 +21,8 @@ org.gradle.kotlin.dsl.precompiled.accessors.strict=true org.gradle.dependency.verification.console=verbose -org.gradle.warning.mode=all org.gradle.parallel=true org.gradle.appname=common-utils -org.gradle.caching=false +org.gradle.caching=true kotlin.code.style=official org.gradle.jvmargs=-Xmx4096m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e8be595..bdc9a83 100755 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/java-utils/build.gradle.kts b/java-utils/build.gradle.kts index c92dc4a..62ec92c 100644 --- a/java-utils/build.gradle.kts +++ b/java-utils/build.gradle.kts @@ -1,6 +1,6 @@ /* - * 🤹 common-utils: Common Kotlin utilities made for my personal usage. - * Copyright (c) 2021-2023 Noel + * 🤹 common-utils: Common Java and Kotlin utilities for Noel's projects ^w^ + * Copyright (c) 2021-2023 Noel Towa * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/java-utils/src/main/java/dev/floofy/utils/java/SetOnce.java b/java-utils/src/main/java/dev/floofy/utils/java/SetOnce.java index ea3dc57..fc4cb9e 100644 --- a/java-utils/src/main/java/dev/floofy/utils/java/SetOnce.java +++ b/java-utils/src/main/java/dev/floofy/utils/java/SetOnce.java @@ -1,6 +1,6 @@ /* - * 🤹 common-utils: Common Kotlin utilities made for my personal usage. - * Copyright (c) 2021-2023 Noel + * 🤹 common-utils: Common Java and Kotlin utilities for Noel's projects ^w^ + * Copyright (c) 2021-2023 Noel Towa * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -76,6 +76,13 @@ public boolean wasSet() { return ref.get() != null; } + /** + * Resets the given value, if needed. + */ + public void reset() { + ref.set(null); + } + @Override public int hashCode() { final var value = ref.get(); diff --git a/java-utils/src/test/java/dev/floofy/utils/java/tests/SetOnceTests.java b/java-utils/src/test/java/dev/floofy/utils/java/tests/SetOnceTests.java index b53cb70..42dd5e5 100644 --- a/java-utils/src/test/java/dev/floofy/utils/java/tests/SetOnceTests.java +++ b/java-utils/src/test/java/dev/floofy/utils/java/tests/SetOnceTests.java @@ -1,6 +1,6 @@ /* - * 🤹 common-utils: Common Kotlin utilities made for my personal usage. - * Copyright (c) 2021-2023 Noel + * 🤹 common-utils: Common Java and Kotlin utilities for Noel's projects ^w^ + * Copyright (c) 2021-2023 Noel Towa * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/settings.gradle.kts b/settings.gradle.kts index 756f430..94c8703 100755 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,6 +1,6 @@ /* - * 🤹 common-utils: Common Kotlin utilities made for my personal usage. - * Copyright (c) 2021-2023 Noel + * 🤹 common-utils: Common Java and Kotlin utilities for Noel's projects ^w^ + * Copyright (c) 2021-2023 Noel Towa * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -21,9 +21,10 @@ * SOFTWARE. */ -rootProject.name = "commons" +rootProject.name = "commons-utils" plugins { + id("org.gradle.toolchains.foojay-resolver-convention") version "0.4.0" id("com.gradle.enterprise") version "3.12.5" } @@ -33,7 +34,7 @@ include( ":extensions-kotlin", ":gradle-utils", ":java-utils", - ":slf4j" + ":slf4j", ) val buildScanServer = System.getProperty("dev.floofy.gradle.build-scan-server", "") ?: "" diff --git a/slf4j/build.gradle.kts b/slf4j/build.gradle.kts index 7b90051..6f52a6f 100644 --- a/slf4j/build.gradle.kts +++ b/slf4j/build.gradle.kts @@ -1,6 +1,6 @@ /* - * 🤹 common-utils: Common Kotlin utilities made for my personal usage. - * Copyright (c) 2021-2023 Noel + * 🤹 common-utils: Common Java and Kotlin utilities for Noel's projects ^w^ + * Copyright (c) 2021-2023 Noel Towa * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal