Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set latest ktlint version #687

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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