diff --git a/build-logic/convention/build.gradle.kts b/build-logic/convention/build.gradle.kts index 9629a6e..0337dd8 100644 --- a/build-logic/convention/build.gradle.kts +++ b/build-logic/convention/build.gradle.kts @@ -33,6 +33,7 @@ dependencies { compileOnly(libs.bundles.asm) implementation(libs.gradlePlugin.spotless) implementation(libs.gradlePlugin.compose.compiler) + implementation(files(libs::class.java.superclass.protectionDomain.codeSource.location)) } gradlePlugin { diff --git a/build-logic/convention/src/main/kotlin/BuildSupportPlugin.kt b/build-logic/convention/src/main/kotlin/BuildSupportPlugin.kt index 1152809..50fc710 100644 --- a/build-logic/convention/src/main/kotlin/BuildSupportPlugin.kt +++ b/build-logic/convention/src/main/kotlin/BuildSupportPlugin.kt @@ -1,5 +1,4 @@ import com.android.build.api.dsl.LibraryExtension -import com.android.build.api.dsl.Lint import com.android.build.api.variant.AndroidComponentsExtension import com.android.build.gradle.BaseExtension import com.android.build.gradle.TestExtension @@ -7,8 +6,7 @@ import com.android.build.gradle.internal.dsl.BaseAppModuleExtension import com.diffplug.gradle.spotless.SpotlessExtension import org.gradle.api.Project import org.gradle.api.tasks.compile.JavaCompile -import org.gradle.kotlin.dsl.configure -import org.gradle.kotlin.dsl.withType +import org.gradle.kotlin.dsl.the import org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.plugin.mpp.Framework @@ -19,19 +17,23 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinJvmCompile class BuildSupportPlugin : BasePlugin() { - override fun apply(project: Project) { - log("apply target: ${project.displayName}") + override fun apply(target: Project) { + log("apply target: ${target.displayName}") - project.group = "com.jithub.app.build-support" - project.version = Versions.versionName + target.group = "com.jithub.app.build-support" + target.version = Versions.versionName - project.configureCommonSpotless() - project.configureCommonAndroid() - project.configureCommonKotlin() - project.configureCommonCompose() + target.configureCommonSpotless() + target.configureCommonAndroid() + target.configureCommonKotlin() + target.configureCommonCompose() } private fun Project.configureCommonSpotless() { + val libs by lazy { + the() + } + plugins.apply("com.diffplug.spotless") val spotless = extensions.getByName("spotless") as SpotlessExtension spotless.apply { @@ -51,13 +53,14 @@ class BuildSupportPlugin : BasePlugin() { trimTrailingWhitespace() endWithNewline() // https://github.com/palantir/palantir-java-format - palantirJavaFormat("2.50.0").style("GOOGLE").formatJavadoc(true) + palantirJavaFormat( + libs.palantirJavaFormat.get().version, + ).style("GOOGLE").formatJavadoc(true) formatAnnotations() licenseHeaderFile(rootProject.file("spotless/copyright.txt")) } // https://github.com/pinterest/ktlint - val ktlintVersion = "1.3.1" kotlin { if (path == ":") { target("**/*.kt") @@ -70,9 +73,9 @@ class BuildSupportPlugin : BasePlugin() { "**/src/commonMain/kotlin/Greeting.kt", "**/src/wasmJsMain/kotlin/Platform.wasmJs.kt", ) - ktlint(ktlintVersion).customRuleSets( + ktlint(libs.ktlint.get().version).customRuleSets( // https://github.com/mrmans0n/compose-rules - listOf("io.nlopez.compose.rules:ktlint:0.4.11"), + listOf("io.nlopez.compose.rules:ktlint:${libs.ktlintComposeRules.get().version}"), ).setEditorConfigPath( "${rootProject.rootDir}/.editorconfig", ).editorConfigOverride( @@ -96,7 +99,9 @@ class BuildSupportPlugin : BasePlugin() { "**/build/**/*.kts", "${rootProject.rootDir}/spotless/**", ) - ktlint(ktlintVersion).setEditorConfigPath("${rootProject.rootDir}/.editorconfig") + ktlint( + libs.ktlint.get().version, + ).setEditorConfigPath("${rootProject.rootDir}/.editorconfig") // Look for the first line that doesn't have a block comment (assumed to be the license) licenseHeaderFile(rootProject.file("spotless/copyright.txt"), "(^(?![\\/ ]\\*).*$)") } @@ -176,21 +181,21 @@ class BuildSupportPlugin : BasePlugin() { with(project) { when (android) { - is BaseAppModuleExtension -> configure { - lint(lintConfigure()) + is BaseAppModuleExtension -> { + android.lint(lintConfigure()) } - is LibraryExtension -> configure { - lint(lintConfigure()) + is LibraryExtension -> { + android.lint(lintConfigure()) } - is TestExtension -> configure { - lint(lintConfigure()) + is TestExtension -> { + android.lint(lintConfigure()) } else -> { pluginManager.apply("com.android.lint") - configure(lintConfigure()) + apply(lintConfigure()) } } } @@ -219,7 +224,7 @@ class BuildSupportPlugin : BasePlugin() { } } - // https://github.com/cashapp/redwood/blob/trunk/build-support/src/main/kotlin/app/cash/redwood/buildsupport/RedwoodBuildPlugin.kt + // https://github.com/cashapp/redwood/blob/trunk/build-support private fun Project.configureCommonKotlin() { tasks.withType(KotlinCompile::class.java).configureEach { compilerOptions { @@ -287,7 +292,7 @@ class BuildSupportPlugin : BasePlugin() { * with the project's Kotlin version. */ private fun Project.configureCommonCompose() { - tasks.withType().configureEach { + tasks.withType(KotlinJsCompile::class.java).configureEach { compilerOptions { freeCompilerArgs.set( freeCompilerArgs.getOrElse(emptyList()) + listOf( diff --git a/build-logic/convention/src/main/kotlin/Configuration.kt b/build-logic/convention/src/main/kotlin/Configuration.kt index 6008a80..cfc6121 100644 --- a/build-logic/convention/src/main/kotlin/Configuration.kt +++ b/build-logic/convention/src/main/kotlin/Configuration.kt @@ -10,9 +10,9 @@ object Versions { private const val majorVersion = 0 private const val minorVersion = 1 - private const val patchVersion = 0 + private const val patchVersion = 1 const val versionName = "$majorVersion.$minorVersion.$patchVersion" - const val versionCode = 2401 + const val versionCode = 2402 val javaVersion = JavaVersion.VERSION_1_8 val jvmTarget = JvmTarget.JVM_1_8 @@ -21,20 +21,16 @@ object Versions { // packaging-resources-excludes object Resources { val excludes = listOf( - "DebugProbesKt.bin", - // "kotlin-tooling-metadata.json", - "kotlin/**", - // Only exclude *.version files in release mode as debug mode requires these files for layout inspector to work. - // "META-INF/*.version", - "META-INF/{AL2.0,LGPL2.1}", - "META-INF/DEPENDENCIES", - "META-INF/DEPENDENCIES.txt", - "META-INF/NOTICE", - "META-INF/NOTICE.txt", - "META-INF/LICENSE", - "META-INF/LICENSE.txt", - "META-INF/INDEX.LIST", - "META-INF/*.kotlin_module", + "**/kotlin-tooling-metadata.json", + "**.properties", + "**.bin", + "**/*.proto", + // https://github.com/Kotlin/kotlinx.coroutines/issues/2023 + "META-INF/**", + "**/attach_hotspot_windows.dll", + // ktor + // "**/custom.config.conf", + // "**/custom.config.yaml", // assets/sentry-external-modules.txt "**/sentry-external-modules.txt", ) diff --git a/build.gradle.kts b/build.gradle.kts index 9fdd1a7..d140b1c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -46,7 +46,7 @@ allprojects { subprojects { afterEvaluate { tasks.withType { - // dependsOn(tasks.getByName("spotlessApply")) + dependsOn(tasks.getByName("spotlessApply")) } } } diff --git a/gradle.properties b/gradle.properties index e83e0f6..f5ec890 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,14 +6,11 @@ org.gradle.configuration-cache=true # Kotlin kotlin.incremental.native=true -#kotlin.js.compiler=ir # This is needed for the JB Compose runtime to link on native targets. They also use this flag # in their samples. Over time it should be removed once they figure out why it was needed. kotlin.native.cacheKind=none -# https://github.com/Kotlin/kotlinx-atomicfu/issues/141 -kotlin.native.ignoreIncorrectDependencies=true kotlin.native.ignoreDisabledTargets=true # MPP diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index fff2a23..c84c588 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -53,6 +53,10 @@ androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-co androidx-test-junit = { group = "androidx.test.ext", name = "junit", version.ref = "androidx-test-junit" } junit = { group = "junit", name = "junit", version.ref = "junit" } +ktlint = "com.pinterest.ktlint:ktlint-cli:1.3.1" +ktlintComposeRules = "io.nlopez.compose.rules:ktlint:0.4.11" +palantirJavaFormat = "com.palantir.javaformat:palantir-java-format:2.50.0" + [plugins] compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }