Skip to content

Commit

Permalink
Merge pull request #2 from ding1dingx/feature/v0.1.1
Browse files Browse the repository at this point in the history
Feature/v0.1.1
  • Loading branch information
syxc authored Sep 3, 2024
2 parents daf068c + 9b2fde2 commit 102e51e
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 45 deletions.
1 change: 1 addition & 0 deletions build-logic/convention/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
55 changes: 30 additions & 25 deletions build-logic/convention/src/main/kotlin/BuildSupportPlugin.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
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
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
Expand All @@ -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<org.gradle.accessors.dm.LibrariesForLibs>()
}

plugins.apply("com.diffplug.spotless")
val spotless = extensions.getByName("spotless") as SpotlessExtension
spotless.apply {
Expand All @@ -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")
Expand All @@ -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(
Expand All @@ -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"), "(^(?![\\/ ]\\*).*$)")
}
Expand Down Expand Up @@ -176,21 +181,21 @@ class BuildSupportPlugin : BasePlugin() {

with(project) {
when (android) {
is BaseAppModuleExtension -> configure<BaseAppModuleExtension> {
lint(lintConfigure())
is BaseAppModuleExtension -> {
android.lint(lintConfigure())
}

is LibraryExtension -> configure<LibraryExtension> {
lint(lintConfigure())
is LibraryExtension -> {
android.lint(lintConfigure())
}

is TestExtension -> configure<TestExtension> {
lint(lintConfigure())
is TestExtension -> {
android.lint(lintConfigure())
}

else -> {
pluginManager.apply("com.android.lint")
configure<Lint>(lintConfigure())
apply(lintConfigure())
}
}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -287,7 +292,7 @@ class BuildSupportPlugin : BasePlugin() {
* with the project's Kotlin version.
*/
private fun Project.configureCommonCompose() {
tasks.withType<KotlinJsCompile>().configureEach {
tasks.withType(KotlinJsCompile::class.java).configureEach {
compilerOptions {
freeCompilerArgs.set(
freeCompilerArgs.getOrElse(emptyList()) + listOf(
Expand Down
28 changes: 12 additions & 16 deletions build-logic/convention/src/main/kotlin/Configuration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
)
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ allprojects {
subprojects {
afterEvaluate {
tasks.withType<JavaCompile> {
// dependsOn(tasks.getByName("spotlessApply"))
dependsOn(tasks.getByName("spotlessApply"))
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

Expand Down

0 comments on commit 102e51e

Please sign in to comment.