Skip to content

Commit

Permalink
Set latest ktlint version (#687)
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszkwiecinski authored Nov 28, 2024
1 parent 2d10803 commit 442a757
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mavencentral-jgit = "7.0.0.202409031743-r"
mavencentral-ktlint-gradle = "0.10.0"
maven-binarycompatiblity = "0.16.3"
maven-dokka = "1.9.20"
maven-ktlint = "1.4.1"

[libraries]
agp-gradle-implementation = { module = "com.android.tools.build:gradle", version.ref = "google-agp" } # TODO remove
Expand All @@ -28,6 +29,7 @@ junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "mav
assertj-core = { module = "org.assertj:assertj-core", version.ref = "mavencentral-assertj" }
eclipse-jgit = { module = "org.eclipse.jgit:org.eclipse.jgit", version.ref = "mavencentral-jgit" }
jetbrains-dokka = { module = "org.jetbrains.dokka:dokka-gradle-plugin", version.ref = "maven-dokka" }
ktlint-cli = { module = "com.pinterest.ktlint:ktlint-cli", version.ref = "maven-ktlint" }

[plugins]
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "mavencentral-kotlin" }
Expand Down
15 changes: 15 additions & 0 deletions quality/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ tasks.named("test") {
useJUnitPlatform()
}

tasks.register("generateVersionProperties", WriteProperties) { writeProps ->
def propertiesFile = new File(sourceSets.main.output.resourcesDir, "starter-quality-gradle-plugin.properties")
if (GradleVersion.current() >= GradleVersion.version("8.1")) {
writeProps.destinationFile = propertiesFile
} else {
//noinspection GrDeprecatedAPIUsage
writeProps.outputFile = propertiesFile
}
writeProps.property("ktlint_version", libs.versions.maven.ktlint)
}

tasks.named("processResources") {
dependsOn("generateVersionProperties")
}

gradlePlugin {
plugins {
quality {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ internal fun Project.configureKtlint() {
pluginManager.apply(KtlintGradlePlugin::class.java)

extensions.configure(KtlintGradleExtension::class.java) {
experimentalRules.set(true)
disabledRules.set(
experimentalRules.convention(true)
disabledRules.convention(
disabledRules.get() + listOf(
"import-ordering",
"filename",
"experimental:function-signature",
"experimental:property-naming",
),
)
ktlintVersion.convention(versionProperties.ktlintVersion())
}

tasks.named(ProjectCodeStyleTask.TASK_NAME) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.project.starter.quality.internal

import java.util.Properties

internal val versionProperties by lazy(::VersionProperties)

internal class VersionProperties : Properties() {
init {
load(this.javaClass.getResourceAsStream("/starter-quality-gradle-plugin.properties"))
}

fun ktlintVersion(): String = getProperty("ktlint_version")
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ internal class QualityPluginTest : WithGradleProjectTest() {
options.release.set(targetJavaVersion.majorVersion.toInteger())
}
tasks.withType(KotlinCompile).configureEach {
compilerOptions.jvmTarget = JvmTarget.@Companion.fromTarget(targetJavaVersion.toString())
compilerOptions.jvmTarget = JvmTarget.fromTarget(targetJavaVersion.toString())
}
repositories.mavenCentral()
Expand Down

0 comments on commit 442a757

Please sign in to comment.