diff --git a/README.md b/README.md index be1fcefd..24aa273a 100644 --- a/README.md +++ b/README.md @@ -64,12 +64,11 @@ open a [new issue](https://github.com/JLLeitschuh/ktlint-gradle/issues/new). This plugin was written using the new API available for the Gradle script Kotlin builds. This API is available in new versions of Gradle. -Minimal supported [Gradle](https://www.gradle.org) version: `6.8` +Minimal supported [Gradle](https://www.gradle.org) version: `7.4.` Minimal supported [Kotlin](https://kotlinlang.org) version: `1.4` -Minimal supported [ktlint](https://github.com/pinterest/ktlint) version: `0.34.0` -(additionally excluding `0.37.0` on Windows OS and `0.38.0`, `0.43.0`, `0.43.1` on all OS types) +Minimal supported [ktlint](https://github.com/pinterest/ktlint) version: `0.47.1` ### Ktlint plugin diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 59250647..5b5c106f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionSha256Sum=b586e04868a22fd817c8971330fec37e298f3242eb85c374181b12d637f80302 -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionSha256Sum=3e1af3ae886920c3ac87f7a91f816c0c7c436f276a6eefdb3da152100fef72ae +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts index f994340f..fc758c2d 100644 --- a/plugin/build.gradle.kts +++ b/plugin/build.gradle.kts @@ -6,14 +6,12 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.util.prefixIfNot plugins { - kotlin("jvm") id("com.gradle.plugin-publish") - `java-gradle-plugin` + `kotlin-dsl` `maven-publish` id("org.jlleitschuh.gradle.ktlint") id("com.github.johnrengelman.shadow") id("com.github.breadmoirai.github-release") - id("org.gradle.test-retry") } val pluginGroup = "org.jlleitschuh.gradle" @@ -60,22 +58,6 @@ configurations["testImplementation"].extendsFrom(shadowImplementation) sourceSets { val adapter by creating { } - val adapter34 by creating { - compileClasspath += adapter.output - } - val adapter34Test by creating { - compileClasspath += adapter.output + adapter34.output - runtimeClasspath += adapter.output + adapter34.output - } - val adapter41 by creating { - compileClasspath += adapter.output - } - val adapter45 by creating { - compileClasspath += adapter.output - } - val adapter46 by creating { - compileClasspath += adapter.output - } val adapter47 by creating { compileClasspath += adapter.output } @@ -93,10 +75,6 @@ sourceSets { } val adapters = listOf( adapter, - adapter34, - adapter41, - adapter45, - adapter46, adapter47, adapter48, adapter49, @@ -118,10 +96,6 @@ sourceSets { } val adapterSources = listOf( sourceSets.named("adapter"), - sourceSets.named("adapter34"), - sourceSets.named("adapter41"), - sourceSets.named("adapter45"), - sourceSets.named("adapter46"), sourceSets.named("adapter47"), sourceSets.named("adapter48"), sourceSets.named("adapter49"), @@ -132,24 +106,11 @@ tasks.named("shadowJar") { this.from(adapterSources.map { sourceSet -> sourceSet.map { it.output.classesDirs } }) } -val test34Task = tasks.register("test34") { - classpath = sourceSets.named("adapter34Test").get().runtimeClasspath - testClassesDirs = sourceSets.named("adapter34Test").get().output.classesDirs -} -tasks.named("test") { - dependsOn(test34Task) -} - dependencies { - compileOnly(gradleApi()) add("adapterCompileOnly", "com.pinterest.ktlint:ktlint-core:0.34.0") add("adapterImplementation", libs.commons.io) add("adapterImplementation", libs.semver) - add("adapter34Implementation", kotlin("reflect")) - add("adapter34CompileOnly", "com.pinterest.ktlint:ktlint-core:0.34.0") - add("adapter41CompileOnly", "com.pinterest.ktlint:ktlint-core:0.41.0") - add("adapter45CompileOnly", "com.pinterest.ktlint:ktlint-core:0.45.2") - add("adapter46CompileOnly", "com.pinterest.ktlint:ktlint-core:0.46.1") + add("adapter47CompileOnly", "com.pinterest.ktlint:ktlint-core:0.47.1") add("adapter48CompileOnly", "com.pinterest.ktlint:ktlint-core:0.48.2") @@ -184,19 +145,11 @@ dependencies { * https://github.com/JLLeitschuh/ktlint-gradle/issues/9 */ - testImplementation(gradleTestKit()) testImplementation(libs.junit.jupiter) testImplementation(libs.assertj.core) testImplementation(libs.kotlin.reflect) testImplementation(libs.ktlint.core) testImplementation(libs.archunit.junit5) - - add("adapter34TestImplementation", "com.pinterest.ktlint:ktlint-core:0.34.0") - add("adapter34TestImplementation", libs.commons.io) - add("adapter34TestImplementation", gradleTestKit()) - add("adapter34TestImplementation", libs.junit.jupiter) - add("adapter34TestImplementation", libs.assertj.core) - add("adapter34TestImplementation", libs.kotlin.reflect) } kotlin { @@ -212,11 +165,11 @@ kotlin { } // Test tasks loods plugin from local maven repository -tasks.named("test").configure { +tasks.named("test") { dependsOn("publishToMavenLocal") } -tasks.withType().configureEach { +tasks.withType() { useJUnitPlatform() maxParallelForks = (Runtime.getRuntime().availableProcessors() / 2).takeIf { it > 0 } ?: 1 doFirst { @@ -235,13 +188,13 @@ tasks.withType().configureEach { showStackTraces = true } - retry { - val isCiServer = System.getenv().containsKey("CI") - if (isCiServer) { - maxRetries.set(2) - maxFailures.set(10) - } - } +// retry { +// val isCiServer = System.getenv().containsKey("CI") +// if (isCiServer) { +// maxRetries.set(2) +// maxFailures.set(10) +// } +// } } val relocateShadowJar = tasks.register("relocateShadowJar") @@ -392,9 +345,6 @@ pluginBundle { "ktlintPlugin" { displayName = "Ktlint Gradle Plugin" } - "ktlintIdeaPlugin" { - displayName = "Ktlint Gradle IntelliJ Configuration Plugin" - } } } diff --git a/plugin/gradle/libs.versions.toml b/plugin/gradle/libs.versions.toml index ee855385..878e46f8 100644 --- a/plugin/gradle/libs.versions.toml +++ b/plugin/gradle/libs.versions.toml @@ -1,12 +1,12 @@ [versions] kotlin = "1.5.31" -ktlint = "0.45.2" # last version prior to API changes. we can increase this more once we drop support for the old API. +ktlint = "0.47.1" # last version prior to API changes. we can increase this more once we drop support for the old API. androidPlugin = "4.1.0" semver = "1.1.1" jgit = "5.6.0.201912101111-r" sl4fj = "1.7.30" -gradleWrapper = "7.3.3" -gradleWrapperSha = "b586e04868a22fd817c8971330fec37e298f3242eb85c374181b12d637f80302" +gradleWrapper = "8.4" +gradleWrapperSha = "3e1af3ae886920c3ac87f7a91f816c0c7c436f276a6eefdb3da152100fef72ae" junit5 = "5.5.2" assertJ = "3.11.1" commonsIo = "2.8.0" diff --git a/plugin/gradle/wrapper/gradle-wrapper.properties b/plugin/gradle/wrapper/gradle-wrapper.properties index 59250647..5b5c106f 100644 --- a/plugin/gradle/wrapper/gradle-wrapper.properties +++ b/plugin/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionSha256Sum=b586e04868a22fd817c8971330fec37e298f3242eb85c374181b12d637f80302 -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip +distributionSha256Sum=3e1af3ae886920c3ac87f7a91f816c0c7c436f276a6eefdb3da152100fef72ae +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/plugin/settings.gradle.kts b/plugin/settings.gradle.kts index 8325a104..d8b23ac0 100644 --- a/plugin/settings.gradle.kts +++ b/plugin/settings.gradle.kts @@ -2,18 +2,15 @@ pluginManagement { val latestRelease = file("VERSION_LATEST_RELEASE.txt").readText().trim() plugins { id("org.jlleitschuh.gradle.ktlint") version latestRelease - id("org.jetbrains.kotlin.jvm") version "1.9.0" + id("org.jetbrains.kotlin.jvm") version "1.9.10" id("com.gradle.plugin-publish") version "0.15.0" `java-gradle-plugin` `maven-publish` id("com.github.johnrengelman.shadow") version "7.0.0" id("com.github.breadmoirai.github-release") version "2.3.7" - id("org.gradle.test-retry") version "1.3.1" } } -enableFeaturePreview("VERSION_CATALOGS") - plugins { `gradle-enterprise` } diff --git a/plugin/src/adapter34/kotlin/org/jlleitschuh/gradle/ktlint/reporter/Ktlint34ReporterProvider.kt b/plugin/src/adapter34/kotlin/org/jlleitschuh/gradle/ktlint/reporter/Ktlint34ReporterProvider.kt deleted file mode 100644 index 7e0470e1..00000000 --- a/plugin/src/adapter34/kotlin/org/jlleitschuh/gradle/ktlint/reporter/Ktlint34ReporterProvider.kt +++ /dev/null @@ -1,13 +0,0 @@ -package org.jlleitschuh.gradle.ktlint.reporter - -import com.pinterest.ktlint.core.ReporterProvider -import java.io.PrintStream - -class Ktlint34ReporterProvider(val reporterProvider: ReporterProvider) : GenericReporterProvider { - override fun get(outputStream: PrintStream, opt: Map): Ktlint34Reporter { - return Ktlint34Reporter(reporterProvider.get(outputStream, opt)) - } - - override val id: String - get() = reporterProvider.id -} diff --git a/plugin/src/adapter34/kotlin/org/jlleitschuh/gradle/ktlint/reporter/SerializableReporterProvider.kt b/plugin/src/adapter34/kotlin/org/jlleitschuh/gradle/ktlint/reporter/SerializableReporterProvider.kt deleted file mode 100644 index eac809ee..00000000 --- a/plugin/src/adapter34/kotlin/org/jlleitschuh/gradle/ktlint/reporter/SerializableReporterProvider.kt +++ /dev/null @@ -1,38 +0,0 @@ -package org.jlleitschuh.gradle.ktlint.reporter - -import com.pinterest.ktlint.core.ReporterProvider -import java.io.IOException -import java.io.ObjectInputStream -import java.io.ObjectOutputStream -import java.io.Serializable -import kotlin.reflect.jvm.jvmName - -/** - * Special wrapper around [ReporterProvider] allowing to serialize/deserialize it into file. - * - * Should be removed once KtLint will add interface implementation into [ReporterProvider]. - */ -class SerializableReporterProvider( - reporterProvider: ReporterProvider -) : Serializable { - @Transient - var reporterProvider: ReporterProvider = reporterProvider - private set - - @Throws(IOException::class) - private fun writeObject(out: ObjectOutputStream) { - out.writeUTF(reporterProvider::class.jvmName) - } - - @Throws(IOException::class, ClassNotFoundException::class) - private fun readObject(oin: ObjectInputStream) { - val reporterProviderClassName = oin.readUTF() - val classLoader = this.javaClass.classLoader - val reporterProviderClass = classLoader.loadClass(reporterProviderClassName) - reporterProvider = reporterProviderClass.newInstance() as ReporterProvider - } - - companion object { - private const val serialVersionUID: Long = 2012021L - } -} diff --git a/plugin/src/adapter34/kotlin/org/jlleitschuh/gradle/ktlint/reporter/SerializableReportersProviderLoader.kt b/plugin/src/adapter34/kotlin/org/jlleitschuh/gradle/ktlint/reporter/SerializableReportersProviderLoader.kt deleted file mode 100644 index 63eb64d8..00000000 --- a/plugin/src/adapter34/kotlin/org/jlleitschuh/gradle/ktlint/reporter/SerializableReportersProviderLoader.kt +++ /dev/null @@ -1,77 +0,0 @@ -package org.jlleitschuh.gradle.ktlint.reporter - -import com.pinterest.ktlint.core.Reporter -import com.pinterest.ktlint.core.ReporterProvider -import java.io.File -import java.io.ObjectInputStream -import java.util.ServiceLoader - -class SerializableReportersProviderLoader : - ReportersLoaderAdapter { - override fun loadAllReporterProviders(): List> = ServiceLoader - .load(ReporterProvider::class.java) - .toList().map { - ReporterProviderWrapper(it.id, SerializableReporterProvider(it)) - } - - override fun loadReporterProviders(serializedReporterProviders: File): List { - return ObjectInputStream( - serializedReporterProviders.inputStream().buffered() - ).use { - @Suppress("UNCHECKED_CAST") - it.readObject() as List - }.map { Ktlint34ReporterProvider(it.reporterProvider) } - } - - override fun loadAllGenericReporterProviders(): List = ServiceLoader - .load(ReporterProvider::class.java) - .toList().map { - Ktlint34ReporterProvider(it) - } - - override fun filterEnabledBuiltInProviders( - enabledReporters: Set, - allProviders: List> - ): List> { - val enabledProviders = allProviders - .filter { reporterProvider -> - enabledReporters.any { - reporterProvider.id == it.reporterName - } - } - return enabledReporters - .map { reporterType -> - val provider = enabledProviders.find { reporterType.reporterName == it.id } - ?: throw RuntimeException( - "KtLint plugin failed to load reporter ${reporterType.reporterName}." - ) - - val options = if (reporterType == ReporterType.PLAIN_GROUP_BY_FILE) { - reporterType.options.associateWith { "true" } - } else { - emptyMap() - } - - LoadedReporter(provider.id, reporterType.fileExtension, options) to provider.reporterProvider - } - } - - override fun filterCustomProviders( - customReporters: Set, - allProviders: List - ): List> { - val customProviders = allProviders - .filter { reporterProvider -> - customReporters.any { reporterProvider.reporterProvider.id == it.reporterId } - } - - return customReporters - .map { customReporter -> - val provider = customProviders.find { customReporter.reporterId == it.reporterProvider.id } - ?: throw RuntimeException( - "KtLint plugin failed to load ${customReporter.reporterId} custom reporter." - ) - LoadedReporter(customReporter.reporterId, customReporter.fileExtension, emptyMap()) to provider - } - } -} diff --git a/plugin/src/adapter34Test/kotlin/org/jlleitschuh/gradle/ktlint/reporter/SerializableReporterProviderTest.kt b/plugin/src/adapter34Test/kotlin/org/jlleitschuh/gradle/ktlint/reporter/SerializableReporterProviderTest.kt deleted file mode 100644 index 3dd679ee..00000000 --- a/plugin/src/adapter34Test/kotlin/org/jlleitschuh/gradle/ktlint/reporter/SerializableReporterProviderTest.kt +++ /dev/null @@ -1,45 +0,0 @@ -package org.jlleitschuh.gradle.ktlint.reporter - -import com.pinterest.ktlint.core.Reporter -import com.pinterest.ktlint.core.ReporterProvider -import org.assertj.core.api.Assertions.assertThat -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.io.TempDir -import java.io.File -import java.io.ObjectInputStream -import java.io.ObjectOutputStream -import java.io.PrintStream - -internal class SerializableReporterProviderTest { - @TempDir - lateinit var temporaryFolder: File - - @Test - internal fun `Should correctly serialize and deserialize ReporterProvider`() { - val reporterProvider: ReporterProvider = TestReporterProvider() - val wrappedReporterProvider = SerializableReporterProvider(reporterProvider) - val serializeIntoFile = temporaryFolder.resolve("reporters.test") - - ObjectOutputStream(serializeIntoFile.outputStream()).use { - it.writeObject(wrappedReporterProvider) - } - - ObjectInputStream(serializeIntoFile.inputStream()).use { - val restoredWrappedReporterProvider = it.readObject() as SerializableReporterProvider - assertThat(restoredWrappedReporterProvider.reporterProvider).isInstanceOf(TestReporterProvider::class.java) - assertThat(restoredWrappedReporterProvider.reporterProvider.id) - .isEqualTo(reporterProvider.id) - } - } - - private class TestReporterProvider : ReporterProvider { - override val id: String = "test-reporter-provider" - - override fun get( - out: PrintStream, - opt: Map - ): Reporter { - TODO("Not yet implemented") - } - } -} diff --git a/plugin/src/adapter41/kotlin/org/jlleitschuh/gradle/ktlint/reporter/Ktlint41Reporter.kt b/plugin/src/adapter41/kotlin/org/jlleitschuh/gradle/ktlint/reporter/Ktlint41Reporter.kt deleted file mode 100644 index ad73b06f..00000000 --- a/plugin/src/adapter41/kotlin/org/jlleitschuh/gradle/ktlint/reporter/Ktlint41Reporter.kt +++ /dev/null @@ -1,30 +0,0 @@ -package org.jlleitschuh.gradle.ktlint.reporter - -import com.pinterest.ktlint.core.Reporter -import org.jlleitschuh.gradle.ktlint.worker.SerializableLintError -import org.jlleitschuh.gradle.ktlint.worker.toCore - -/** - * implementation of GenericReporter for the Reporter ktlint class - */ -class Ktlint41Reporter(val reporter: Reporter) : GenericReporter { - override fun beforeAll() { - reporter.beforeAll() - } - - override fun before(file: String) { - reporter.before(file) - } - - override fun onLintError(file: String, err: SerializableLintError, corrected: Boolean) { - reporter.onLintError(file, err.toCore(), corrected) - } - - override fun after(file: String) { - reporter.after(file) - } - - override fun afterAll() { - reporter.afterAll() - } -} diff --git a/plugin/src/adapter41/kotlin/org/jlleitschuh/gradle/ktlint/reporter/Ktlint41ReporterProvider.kt b/plugin/src/adapter41/kotlin/org/jlleitschuh/gradle/ktlint/reporter/Ktlint41ReporterProvider.kt deleted file mode 100644 index 0f7331db..00000000 --- a/plugin/src/adapter41/kotlin/org/jlleitschuh/gradle/ktlint/reporter/Ktlint41ReporterProvider.kt +++ /dev/null @@ -1,13 +0,0 @@ -package org.jlleitschuh.gradle.ktlint.reporter - -import com.pinterest.ktlint.core.ReporterProvider -import java.io.PrintStream - -class Ktlint41ReporterProvider(val reporterProvider: ReporterProvider) : GenericReporterProvider { - override fun get(outputStream: PrintStream, opt: Map): Ktlint41Reporter { - return Ktlint41Reporter(reporterProvider.get(outputStream, opt)) - } - - override val id: String - get() = reporterProvider.id -} diff --git a/plugin/src/adapter45/kotlin/org/jlleitschuh/gradle/ktlint/worker/BaselineLoader45.kt b/plugin/src/adapter45/kotlin/org/jlleitschuh/gradle/ktlint/worker/BaselineLoader45.kt deleted file mode 100644 index 8d82a82d..00000000 --- a/plugin/src/adapter45/kotlin/org/jlleitschuh/gradle/ktlint/worker/BaselineLoader45.kt +++ /dev/null @@ -1,9 +0,0 @@ -package org.jlleitschuh.gradle.ktlint.worker - -import com.pinterest.ktlint.core.internal.loadBaseline - -class BaselineLoader45 : BaselineLoader { - override fun loadBaselineRules(path: String): Map> { - return loadBaseline(path).baselineRules?.mapValues { it.value.map { it.toSerializable() } } ?: emptyMap() - } -} diff --git a/plugin/src/adapter45/kotlin/org/jlleitschuh/gradle/ktlint/worker/KtLintInvocation45.kt b/plugin/src/adapter45/kotlin/org/jlleitschuh/gradle/ktlint/worker/KtLintInvocation45.kt deleted file mode 100644 index c42e1e18..00000000 --- a/plugin/src/adapter45/kotlin/org/jlleitschuh/gradle/ktlint/worker/KtLintInvocation45.kt +++ /dev/null @@ -1,80 +0,0 @@ -package org.jlleitschuh.gradle.ktlint.worker - -import com.pinterest.ktlint.core.KtLint -import com.pinterest.ktlint.core.LintError -import com.pinterest.ktlint.core.RuleSet -import com.pinterest.ktlint.core.RuleSetProvider -import java.io.File -import java.util.ServiceLoader - -class KtLintInvocation45( - private val editorConfigPath: String?, - private val ruleSets: Set, - private val userData: Map, - private val debug: Boolean -) : KtLintInvocation { - companion object Factory : KtLintInvocationFactory { - fun initialize( - editorConfigPath: String?, - enableExperimental: Boolean, - disabledRules: Set, - userData: Map, - debug: Boolean - ): KtLintInvocation = KtLintInvocation45( - editorConfigPath = editorConfigPath, - ruleSets = loadRuleSetsFromClasspathWithRuleSetProvider() - .filterRules(enableExperimental, disabledRules), - userData = userData, - debug = debug - ) - } - - private fun buildParams(file: File, cb: (LintError, Boolean) -> Unit): KtLint.Params { - val script = !file.name.endsWith(".kt", ignoreCase = true) - return KtLint.Params( - fileName = file.absolutePath, - text = file.readText(), - ruleSets = ruleSets, - userData = userData, - debug = debug, - editorConfigPath = editorConfigPath, - script = script, - cb = cb - ) - } - - override fun invokeLint(file: File): LintErrorResult { - val errors = mutableListOf>() - KtLint.lint( - buildParams(file) { le, boolean -> - errors.add(le.toSerializable() to boolean) - } - ) - return LintErrorResult(file, errors) - } - - override fun invokeFormat(file: File): Pair { - val errors = mutableListOf>() - val newCode = KtLint.format( - buildParams(file) { le, boolean -> - errors.add(le.toSerializable() to boolean) - } - ) - return newCode to LintErrorResult(file, errors) - } - - override fun trimMemory() { - KtLint.trimMemory() - } -} - -private fun loadRuleSetsFromClasspathWithRuleSetProvider(): Map { - return ServiceLoader - .load(RuleSetProvider::class.java) - .associateBy { - val key = it.get().id - // Adapted from KtLint CLI module - if (key == "standard") "\u0000$key" else key - } - .mapValues { it.value.get() } -} diff --git a/plugin/src/adapter46/kotlin/org/jlleitschuh/gradle/ktlint/worker/BaselineLoader46.kt b/plugin/src/adapter46/kotlin/org/jlleitschuh/gradle/ktlint/worker/BaselineLoader46.kt deleted file mode 100644 index 0ea676e5..00000000 --- a/plugin/src/adapter46/kotlin/org/jlleitschuh/gradle/ktlint/worker/BaselineLoader46.kt +++ /dev/null @@ -1,9 +0,0 @@ -package org.jlleitschuh.gradle.ktlint.worker - -import com.pinterest.ktlint.core.internal.loadBaseline - -class BaselineLoader46 : BaselineLoader { - override fun loadBaselineRules(path: String): Map> { - return loadBaseline(path).baselineRules?.mapValues { it.value.map { it.toSerializable() } } ?: emptyMap() - } -} diff --git a/plugin/src/adapter46/kotlin/org/jlleitschuh/gradle/ktlint/worker/KtLintInvocation46.kt b/plugin/src/adapter46/kotlin/org/jlleitschuh/gradle/ktlint/worker/KtLintInvocation46.kt deleted file mode 100644 index 802e7ac8..00000000 --- a/plugin/src/adapter46/kotlin/org/jlleitschuh/gradle/ktlint/worker/KtLintInvocation46.kt +++ /dev/null @@ -1,104 +0,0 @@ -package org.jlleitschuh.gradle.ktlint.worker - -import com.pinterest.ktlint.core.KtLint -import com.pinterest.ktlint.core.LintError -import com.pinterest.ktlint.core.RuleSet -import com.pinterest.ktlint.core.RuleSetProvider -import com.pinterest.ktlint.core.api.DefaultEditorConfigProperties -import com.pinterest.ktlint.core.api.EditorConfigOverride -import java.io.File -import java.util.ServiceLoader - -class KtLintInvocation46( - private val editorConfigPath: String?, - private val ruleSets: Set, - private val userData: Map, - private val debug: Boolean -) : KtLintInvocation { - companion object Factory : KtLintInvocationFactory { - fun initialize( - editorConfigPath: String?, - enableExperimental: Boolean, - disabledRules: Set, - userData: Map, - debug: Boolean - ): KtLintInvocation = KtLintInvocation46( - editorConfigPath = editorConfigPath, - ruleSets = loadRuleSetsFromClasspathWithRuleSetProvider() - .filterRules(enableExperimental, disabledRules), - userData = userData, - debug = debug - ) - } - - private fun buildParams( - file: File, - cb: (LintError, Boolean) -> Unit - ): KtLint.ExperimentalParams { - val script = !file.name.endsWith(".kt", ignoreCase = true) - return KtLint.ExperimentalParams( - fileName = file.absolutePath, - text = file.readText(), - ruleSets = ruleSets, - cb = cb, - script = script, - editorConfigPath = editorConfigPath, - debug = debug, - editorConfigOverride = userDataToEditorConfigOverride(userData) - ) - } - - override fun invokeLint(file: File): LintErrorResult { - val errors = mutableListOf>() - KtLint.lint( - buildParams(file) { le, boolean -> - errors.add(le.toSerializable() to boolean) - } - ) - return LintErrorResult(file, errors) - } - - override fun invokeFormat(file: File): Pair { - val errors = mutableListOf>() - val newCode = KtLint.format( - buildParams(file) { le, boolean -> - errors.add(le.toSerializable() to boolean) - } - ) - return newCode to LintErrorResult(file, errors) - } - - override fun trimMemory() { - KtLint.trimMemory() - } -} - -internal fun LintError.toSerializable(): SerializableLintError { - return SerializableLintError(line, col, ruleId, detail, canBeAutoCorrected) -} - -private fun userDataToEditorConfigOverride(userData: Map): EditorConfigOverride { - val codeStyle = if (userData["android"]?.toBoolean() == true) { - DefaultEditorConfigProperties.CodeStyleValue.android - } else { - DefaultEditorConfigProperties.CodeStyleValue.official - } - if (!userData["disabled_rules"].isNullOrBlank()) { - return EditorConfigOverride.from( - DefaultEditorConfigProperties.codeStyleSetProperty to codeStyle, - DefaultEditorConfigProperties.disabledRulesProperty to userData["disabled_rules"] - ) - } - return EditorConfigOverride.from(DefaultEditorConfigProperties.codeStyleSetProperty to codeStyle) -} - -private fun loadRuleSetsFromClasspathWithRuleSetProvider(): Map { - return ServiceLoader - .load(RuleSetProvider::class.java) - .associateBy { - val key = it.get().id - // Adapted from KtLint CLI module - if (key == "standard") "\u0000$key" else key - } - .mapValues { it.value.get() } -} diff --git a/plugin/src/adapter34/kotlin/org/jlleitschuh/gradle/ktlint/reporter/Ktlint34Reporter.kt b/plugin/src/adapter47/kotlin/org/jlleitschuh/gradle/ktlint/reporter/LegacyKtlintReporter.kt similarity index 89% rename from plugin/src/adapter34/kotlin/org/jlleitschuh/gradle/ktlint/reporter/Ktlint34Reporter.kt rename to plugin/src/adapter47/kotlin/org/jlleitschuh/gradle/ktlint/reporter/LegacyKtlintReporter.kt index 783e45a9..cce983b2 100644 --- a/plugin/src/adapter34/kotlin/org/jlleitschuh/gradle/ktlint/reporter/Ktlint34Reporter.kt +++ b/plugin/src/adapter47/kotlin/org/jlleitschuh/gradle/ktlint/reporter/LegacyKtlintReporter.kt @@ -7,7 +7,7 @@ import org.jlleitschuh.gradle.ktlint.worker.toCore /** * implementation of GenericReporter for the Reporter ktlint class */ -class Ktlint34Reporter(val reporter: Reporter) : GenericReporter { +class LegacyKtlintReporter(val reporter: Reporter) : GenericReporter { override fun beforeAll() { reporter.beforeAll() } diff --git a/plugin/src/adapter47/kotlin/org/jlleitschuh/gradle/ktlint/reporter/LegacyKtlintReporterProvider.kt b/plugin/src/adapter47/kotlin/org/jlleitschuh/gradle/ktlint/reporter/LegacyKtlintReporterProvider.kt new file mode 100644 index 00000000..56fad011 --- /dev/null +++ b/plugin/src/adapter47/kotlin/org/jlleitschuh/gradle/ktlint/reporter/LegacyKtlintReporterProvider.kt @@ -0,0 +1,16 @@ +package org.jlleitschuh.gradle.ktlint.reporter + +import com.pinterest.ktlint.core.Reporter +import com.pinterest.ktlint.core.ReporterProvider +import java.io.PrintStream + +class LegacyKtlintReporterProvider( + val reporterProvider: ReporterProvider +) : GenericReporterProvider { + override fun get(outputStream: PrintStream, opt: Map): LegacyKtlintReporter { + return LegacyKtlintReporter(reporterProvider.get(outputStream, opt)) + } + + override val id: String + get() = reporterProvider.id +} diff --git a/plugin/src/adapter41/kotlin/org/jlleitschuh/gradle/ktlint/reporter/ReportersProviderLoader.kt b/plugin/src/adapter47/kotlin/org/jlleitschuh/gradle/ktlint/reporter/ReportersProviderLoader.kt similarity index 78% rename from plugin/src/adapter41/kotlin/org/jlleitschuh/gradle/ktlint/reporter/ReportersProviderLoader.kt rename to plugin/src/adapter47/kotlin/org/jlleitschuh/gradle/ktlint/reporter/ReportersProviderLoader.kt index 1a0013e2..616da1af 100644 --- a/plugin/src/adapter41/kotlin/org/jlleitschuh/gradle/ktlint/reporter/ReportersProviderLoader.kt +++ b/plugin/src/adapter47/kotlin/org/jlleitschuh/gradle/ktlint/reporter/ReportersProviderLoader.kt @@ -7,32 +7,32 @@ import java.io.ObjectInputStream import java.util.ServiceLoader class ReportersProviderLoader : - ReportersLoaderAdapter { - override fun loadAllReporterProviders(): List> = ServiceLoader + ReportersLoaderAdapter, LegacyKtlintReporter, LegacyKtlintReporterProvider> { + override fun loadAllReporterProviders(): List>> = ServiceLoader .load(ReporterProvider::class.java) .toList().map { ReporterProviderWrapper(it.id, it) } - override fun loadAllGenericReporterProviders(): List = ServiceLoader + override fun loadAllGenericReporterProviders(): List = ServiceLoader .load(ReporterProvider::class.java) .toList().map { - Ktlint41ReporterProvider(it) + LegacyKtlintReporterProvider(it) } - override fun loadReporterProviders(serializedReporterProviders: File): List { + override fun loadReporterProviders(serializedReporterProviders: File): List { return ObjectInputStream( serializedReporterProviders.inputStream().buffered() ).use { @Suppress("UNCHECKED_CAST") - it.readObject() as List - }.map { Ktlint41ReporterProvider(it) } + it.readObject() as List> + }.map { LegacyKtlintReporterProvider(it) } } override fun filterEnabledBuiltInProviders( enabledReporters: Set, - allProviders: List> - ): List> { + allProviders: List>> + ): List>> { val enabledProviders = allProviders .filter { reporterProvider -> enabledReporters.any { @@ -58,8 +58,8 @@ class ReportersProviderLoader : override fun filterCustomProviders( customReporters: Set, - allProviders: List - ): List> { + allProviders: List> + ): List>> { val customProviders = allProviders .filter { reporterProvider -> customReporters.any { reporterProvider.id == it.reporterId } diff --git a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/Configurations.kt b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/Configurations.kt index e1baf3cf..00f1589a 100644 --- a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/Configurations.kt +++ b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/Configurations.kt @@ -34,7 +34,7 @@ internal fun createKtlintConfiguration(target: Project, extension: KtlintExtensi // Starting from KtLint 0.41.0 version published artifact has two variants: "external" and "shadowed" attributes { - it.attribute(Bundling.BUNDLING_ATTRIBUTE, target.objects.named(Bundling::class.java, Bundling.EXTERNAL)) + attribute(Bundling.BUNDLING_ATTRIBUTE, target.objects.named(Bundling::class.java, Bundling.EXTERNAL)) } // Workaround for gradle 6 https://github.com/gradle/gradle/issues/13255 @@ -99,7 +99,7 @@ internal fun createKtLintReporterConfiguration( extension .reporterExtension .customReporters - .all { + .forEach { dependencies.addLater( target.provider { val reporterDependency = it.dependency @@ -159,13 +159,9 @@ internal fun createKtLintBaselineReporterConfiguration( // this transitive dep was introduced in ktlint 1.0, but for some reason, it is not picked up automatically target.dependencies.create("io.github.oshai:kotlin-logging:5.1.0") ) - } else if (SemVer.parse(ktlintVersion) >= SemVer(0, 41, 0)) { + } else { // Baseline reporter is only available starting 0.41.0 release listOf(target.dependencies.create("com.pinterest.ktlint:ktlint-reporter-baseline:$version")) - } else { - // Adding fake plain reporter as addLater() does not accept `null` value - // Generate baseline tasks anyway will not run on KtLint versions < 0.41.0 - listOf(target.dependencies.create("com.pinterest.ktlint:ktlint-reporter-plain:$version")) } } ) @@ -177,51 +173,5 @@ private fun Configuration.ensureConsistencyWith( target: Project, otherConfiguration: Configuration ) { - if (GradleVersion.version(target.gradle.gradleVersion) >= GradleVersion.version("6.8")) { - shouldResolveConsistentlyWith(otherConfiguration) - } else { - // Inspired by - // https://android.googlesource.com/platform/tools/base/+/refs/heads/mirror-goog-studio-master-dev/build-system/gradle-core/src/main/java/com/android/build/gradle/internal/dependency/ConstraintHandler.kt - incoming.beforeResolve { - val configName = it.name - otherConfiguration.incoming.resolutionResult.allDependencies { dependency -> - if (dependency is ResolvedDependencyResult) { - val id = dependency.selected.id - if (id is ModuleComponentIdentifier) { - // using a repository with a flatDir to stock local AARs will result in an - // external module dependency with no version. - if (!id.version.isNullOrEmpty()) { - if (id.module != "listenablefuture" || - id.group != "com.google.guava" || - id.version != "1.0" - ) { - target.dependencies.constraints.add( - configName, - "${id.group}:${id.module}:${id.version}" - ) { constraint -> - constraint.because("${otherConfiguration.name} uses version ${id.version}") - constraint.version { versionConstraint -> - versionConstraint.strictly(id.version) - } - } - } - } - } else if (id is ProjectComponentIdentifier && - id.build.isCurrentBuild && - dependency.requested is ModuleComponentSelector - ) { - // Requested external library has been replaced with the project dependency, so - // add the project dependency to the target configuration, so it can be chosen - // instead of the external library as well. - // We should avoid doing this for composite builds, so we check if the selected - // project is from the current build. - target.dependencies.add( - configName, - target.dependencies.project(mapOf("path" to id.projectPath)) - ) - } - } - } - } - } + shouldResolveConsistentlyWith(otherConfiguration) } diff --git a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/GitHook.kt b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/GitHook.kt index 607874ae..af168342 100644 --- a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/GitHook.kt +++ b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/GitHook.kt @@ -114,12 +114,12 @@ private fun KtlintPlugin.PluginHolder.addInstallGitHookFormatTask() { INSTALL_GIT_HOOK_FORMAT_TASK, KtlintInstallGitHookTask::class.java ) { - it.description = "Adds git hook to run ktlintFormat on changed files" - it.group = HELP_GROUP - it.taskName.set(FORMAT_PARENT_TASK_NAME) + description = "Adds git hook to run ktlintFormat on changed files" + group = HELP_GROUP + taskName.set(FORMAT_PARENT_TASK_NAME) // Format git hook will automatically add back updated files to git commit - it.shouldUpdateCommit.set(true) - it.hookName.set("pre-commit") + shouldUpdateCommit.set(true) + hookName.set("pre-commit") } } @@ -128,11 +128,11 @@ private fun KtlintPlugin.PluginHolder.addInstallGitHookCheckTask() { INSTALL_GIT_HOOK_CHECK_TASK, KtlintInstallGitHookTask::class.java ) { - it.description = "Adds git hook to run ktlintCheck on changed files" - it.group = HELP_GROUP - it.taskName.set(CHECK_PARENT_TASK_NAME) - it.shouldUpdateCommit.set(false) - it.hookName.set("pre-commit") + description = "Adds git hook to run ktlintCheck on changed files" + group = HELP_GROUP + taskName.set(CHECK_PARENT_TASK_NAME) + shouldUpdateCommit.set(false) + hookName.set("pre-commit") } } diff --git a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/KtLintCompatibility.kt b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/KtLintCompatibility.kt index 889a31b9..f2251dee 100644 --- a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/KtLintCompatibility.kt +++ b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/KtLintCompatibility.kt @@ -5,16 +5,11 @@ import org.gradle.api.GradleException import org.jlleitschuh.gradle.ktlint.reporter.ReportersLoaderAdapter import org.jlleitschuh.gradle.ktlint.reporter.ReportersProviderLoader import org.jlleitschuh.gradle.ktlint.reporter.ReportersProviderV2Loader -import org.jlleitschuh.gradle.ktlint.reporter.SerializableReportersProviderLoader import org.jlleitschuh.gradle.ktlint.worker.BaselineLoader -import org.jlleitschuh.gradle.ktlint.worker.BaselineLoader45 -import org.jlleitschuh.gradle.ktlint.worker.BaselineLoader46 import org.jlleitschuh.gradle.ktlint.worker.BaselineLoader47 import org.jlleitschuh.gradle.ktlint.worker.BaselineLoader48 import org.jlleitschuh.gradle.ktlint.worker.BaselineLoader49 import org.jlleitschuh.gradle.ktlint.worker.KtLintInvocation100 -import org.jlleitschuh.gradle.ktlint.worker.KtLintInvocation45 -import org.jlleitschuh.gradle.ktlint.worker.KtLintInvocation46 import org.jlleitschuh.gradle.ktlint.worker.KtLintInvocation47 import org.jlleitschuh.gradle.ktlint.worker.KtLintInvocation48 import org.jlleitschuh.gradle.ktlint.worker.KtLintInvocation49 @@ -25,11 +20,7 @@ import java.io.Serializable internal fun selectInvocation(version: String): KtLintInvocationFactory { val semVer = SemVer.parse(version) return if (semVer.major == 0) { - if (semVer.minor < 46) { - KtLintInvocation45 - } else if (semVer.minor == 46) { - KtLintInvocation46 - } else if (semVer.minor == 47) { + if (semVer.minor == 47) { KtLintInvocation47 } else if (semVer.minor == 48) { KtLintInvocation48 @@ -46,11 +37,7 @@ internal fun selectInvocation(version: String): KtLintInvocationFactory { internal fun selectBaselineLoader(version: String): BaselineLoader { val semVer = SemVer.parse(version) return if (semVer.major == 0) { - if (semVer.minor < 46) { - BaselineLoader45() - } else if (semVer.minor == 46) { - BaselineLoader46() - } else if (semVer.minor == 47) { + if (semVer.minor == 47) { BaselineLoader47() } else if (semVer.minor == 48) { BaselineLoader48() @@ -71,9 +58,7 @@ internal fun selectBaselineLoader(version: String): BaselineLoader { internal fun selectReportersLoaderAdapter(version: String): ReportersLoaderAdapter<*, out Serializable, *, *> { val semVer = SemVer.parse(version) return if (semVer.major == 0) { - if (semVer.minor < 41) { - SerializableReportersProviderLoader() - } else if (semVer.minor < 49) { + if (semVer.minor < 49) { ReportersProviderLoader() } else { ReportersProviderV2Loader() diff --git a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/KtlintApplyToIdeaTask.kt b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/KtlintApplyToIdeaTask.kt deleted file mode 100644 index f5322429..00000000 --- a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/KtlintApplyToIdeaTask.kt +++ /dev/null @@ -1,76 +0,0 @@ -package org.jlleitschuh.gradle.ktlint - -import net.swiftzer.semver.SemVer -import org.gradle.api.DefaultTask -import org.gradle.api.file.ConfigurableFileCollection -import org.gradle.api.model.ObjectFactory -import org.gradle.api.provider.Property -import org.gradle.api.tasks.Classpath -import org.gradle.api.tasks.Input -import org.gradle.api.tasks.TaskAction -import javax.inject.Inject - -@Suppress("UnstableApiUsage") -open class KtlintApplyToIdeaTask @Inject constructor( - objectFactory: ObjectFactory -) : DefaultTask() { - - @get:Classpath - val classpath: ConfigurableFileCollection = project.files() - - @get:Input - val android: Property = objectFactory.property() - - @get:Input - val globally: Property = objectFactory.property() - - @get:Input - val ktlintVersion: Property = objectFactory.property() - - @TaskAction - fun generate() { - // this option was removed and will cause errors in ktlint >= 0.47.0 - if (SemVer.parse(ktlintVersion.get()) < SemVer(0, 47, 0)) { - project.javaexec { - it.classpath = classpath - it.main = "com.pinterest.ktlint.Main" - - // Global flags - if (android.get()) { - it.args( - "--android" - ) - } - - // Subcommand - if (globally.get()) { - it.args(getApplyToIdeaCommand()) - } else { - it.args(getApplyToProjectCommand()) - } - - // Subcommand parameters - // -y here to auto-overwrite existing IDEA code style. - it.args("-y") - } - } else { - project.logger.warn( - "Skipping ${this.name}. The applyToIDEA functionality was removed from ktlint in 0.47.0. Use .editorconfig to synchronize formatting rules between IDEA and ktlint." - ) - } - } - - private fun getApplyToIdeaCommand() = - if (SemVer.parse(ktlintVersion.get()) >= SemVer(0, 35, 0)) { - "applyToIDEA" - } else { - "--apply-to-idea" - } - - private fun getApplyToProjectCommand() = - if (SemVer.parse(ktlintVersion.get()) >= SemVer(0, 35, 0)) { - "applyToIDEAProject" - } else { - "--apply-to-idea-project" - } -} diff --git a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/KtlintBasePlugin.kt b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/KtlintBasePlugin.kt index ce84ff20..86af4757 100644 --- a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/KtlintBasePlugin.kt +++ b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/KtlintBasePlugin.kt @@ -30,8 +30,8 @@ open class KtlintBasePlugin : Plugin { } val kotlinScriptAdditionalPathApplier: KotlinScriptAdditionalPathApplier = { additionalFileTree -> - val configureAction = Action { task -> - with(task as BaseKtLintCheckTask) { + val configureAction = Action { + with(this as BaseKtLintCheckTask) { source( additionalFileTree.also { it.include("*.kts") @@ -63,6 +63,6 @@ open class KtlintBasePlugin : Plugin { } companion object { - const val LOWEST_SUPPORTED_GRADLE_VERSION = "6.8" + const val LOWEST_SUPPORTED_GRADLE_VERSION = "7.4.2" } } diff --git a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/KtlintExtension.kt b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/KtlintExtension.kt index 4b2a147a..afd86506 100644 --- a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/KtlintExtension.kt +++ b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/KtlintExtension.kt @@ -36,7 +36,7 @@ internal constructor( /** * The version of KtLint to use. */ - val version: Property = objectFactory.property { set("0.47.1") } + val version: Property = objectFactory.property { set("1.0.1") } /** * Enable relative paths in reports @@ -104,10 +104,8 @@ internal constructor( } /** - * Provide additional `.editorconfig` file, that are not in the project or project parent folders. + * Provide additional `.editorconfig` properties, that are not in the project or project parent folders. */ - @Deprecated("not supported with ktlint 0.47+") - val additionalEditorconfigFile: RegularFileProperty = objectFactory.fileProperty() val additionalEditorconfig: MapProperty = objectFactory.mapProperty(String::class.java, String::class.java) .apply { diff --git a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/KtlintIdeaPlugin.kt b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/KtlintIdeaPlugin.kt deleted file mode 100644 index 96e29006..00000000 --- a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/KtlintIdeaPlugin.kt +++ /dev/null @@ -1,44 +0,0 @@ -package org.jlleitschuh.gradle.ktlint - -import org.gradle.api.Plugin -import org.gradle.api.Project - -/** - * Adds tasks associated with configuring IntelliJ IDEA. - */ -open class KtlintIdeaPlugin : Plugin { - override fun apply(target: Project) { - val extension = target.plugins.apply(KtlintBasePlugin::class.java).extension - - if (target == target.rootProject) { - /* - * Only add these tasks if we are applying to the root project. - */ - addApplyToIdeaTasks(target, extension) - } - } - - private fun addApplyToIdeaTasks(rootProject: Project, extension: KtlintExtension) { - val ktLintConfig = createKtlintConfiguration(rootProject, extension) - - rootProject.registerTask(APPLY_TO_IDEA_TASK_NAME) { - group = HELP_GROUP - description = "Generates IDEA built-in formatter rules and apply them to the project." + - "It will overwrite existing ones." - classpath.setFrom(ktLintConfig) - android.set(extension.android) - globally.set(rootProject.provider { false }) - ktlintVersion.set(extension.version) - } - - rootProject.registerTask(APPLY_TO_IDEA_GLOBALLY_TASK_NAME) { - group = HELP_GROUP - description = "Generates IDEA built-in formatter rules and apply them globally " + - "(in IDEA user settings folder). It will overwrite existing ones." - classpath.setFrom(ktLintConfig) - android.set(extension.android) - globally.set(rootProject.provider { true }) - ktlintVersion.set(extension.version) - } - } -} diff --git a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/KtlintPlugin.kt b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/KtlintPlugin.kt index 626b22a5..e7d30eef 100644 --- a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/KtlintPlugin.kt +++ b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/KtlintPlugin.kt @@ -5,6 +5,7 @@ import org.gradle.api.Project import org.gradle.api.Task import org.gradle.api.artifacts.Configuration import org.gradle.api.tasks.TaskProvider +import org.gradle.kotlin.dsl.getByName import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType @@ -20,9 +21,6 @@ open class KtlintPlugin : Plugin { override fun apply(target: Project) { val holder = PluginHolder(target) - // Apply the idea plugin - target.plugins.apply(KtlintIdeaPlugin::class.java) - holder.addKotlinScriptTasks() holder.addKtLintTasksToKotlinPlugin() holder.addGenerateBaselineTask() @@ -42,7 +40,7 @@ open class KtlintPlugin : Plugin { private fun PluginHolder.applyKtlintMultiplatform(): (Plugin) -> Unit = { val multiplatformExtension = target.extensions.getByType(KotlinMultiplatformExtension::class.java) - multiplatformExtension.sourceSets.all { sourceSet -> + multiplatformExtension.sourceSets.forEach { sourceSet -> val checkTask = createCheckTask( this, sourceSet.name, @@ -73,7 +71,7 @@ open class KtlintPlugin : Plugin { addGenerateReportsTaskToProjectMetaFormatTask(generateReportsFormatTask) } - multiplatformExtension.targets.all { kotlinTarget -> + multiplatformExtension.targets.forEach { kotlinTarget -> if (kotlinTarget.platformType == KotlinPlatformType.androidJvm) { applyKtLintToAndroid() } @@ -81,16 +79,16 @@ open class KtlintPlugin : Plugin { } private fun PluginHolder.applyKtLint(): (Plugin) -> Unit = { - target.extensions.configure("kotlin") { extension -> - extension.sourceSets.all { sourceSet -> + target.extensions.configure(KotlinProjectExtension::class.java) { + sourceSets.forEach { sourceSet -> val kotlinSourceDirectories = sourceSet.kotlin.sourceDirectories val checkTask = createCheckTask( - this, + this@applyKtLint, sourceSet.name, kotlinSourceDirectories ) val generateReportsCheckTask = createGenerateReportsTask( - this, + this@applyKtLint, checkTask, GenerateReportsTask.LintType.CHECK, sourceSet.name @@ -100,12 +98,12 @@ open class KtlintPlugin : Plugin { setCheckTaskDependsOnGenerateReportsTask(generateReportsCheckTask) val formatTask = createFormatTask( - this, + this@applyKtLint, sourceSet.name, kotlinSourceDirectories ) val generateReportsFormatTask = createGenerateReportsTask( - this, + this@applyKtLint, formatTask, GenerateReportsTask.LintType.FORMAT, sourceSet.name diff --git a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/PluginUtil.kt b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/PluginUtil.kt index 6a7b19c8..406d5f5c 100644 --- a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/PluginUtil.kt +++ b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/PluginUtil.kt @@ -15,6 +15,7 @@ import org.gradle.api.provider.Property import org.gradle.api.provider.Provider import org.gradle.api.provider.SetProperty import org.gradle.api.tasks.TaskProvider +import org.gradle.kotlin.dsl.register import org.gradle.language.base.plugins.LifecycleBasePlugin import java.io.File import java.nio.file.Files @@ -26,9 +27,9 @@ internal inline fun Project.registerTask( noinline configuration: T.() -> Unit ): TaskProvider { return tasks - .register(name, T::class.java, *constructorArguments) + .register(name, *constructorArguments) .apply { - configure { configuration(it) } + this.configure(configuration) } } @@ -86,8 +87,6 @@ internal const val FORMATTING_GROUP = "Formatting" internal const val HELP_GROUP = HelpTasksPlugin.HELP_GROUP internal const val CHECK_PARENT_TASK_NAME = "ktlintCheck" internal const val FORMAT_PARENT_TASK_NAME = "ktlintFormat" -internal const val APPLY_TO_IDEA_TASK_NAME = "ktlintApplyToIdea" -internal const val APPLY_TO_IDEA_GLOBALLY_TASK_NAME = "ktlintApplyToIdeaGlobally" internal const val INSTALL_GIT_HOOK_CHECK_TASK = "addKtlintCheckGitPreCommitHook" internal const val INSTALL_GIT_HOOK_FORMAT_TASK = "addKtlintFormatGitPreCommitHook" internal val KOTLIN_EXTENSIONS = listOf("kt", "kts") @@ -125,9 +124,9 @@ internal fun Logger.logKtLintDebugMessage( } internal fun checkMinimalSupportedKtLintVersion(ktLintVersion: String) { - if (SemVer.parse(ktLintVersion) < SemVer(0, 34, 0)) { + if (SemVer.parse(ktLintVersion) < SemVer(0, 47, 1)) { throw GradleException( - "KtLint versions less than 0.34.0 are not supported. " + + "KtLint versions less than 0.47.1 are not supported. " + "Detected KtLint version: $ktLintVersion." ) } diff --git a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/TaskCreation.kt b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/TaskCreation.kt index 1fc92109..727d8e2f 100644 --- a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/TaskCreation.kt +++ b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/TaskCreation.kt @@ -5,6 +5,7 @@ import org.gradle.api.file.FileTree import org.gradle.api.tasks.TaskCollection import org.gradle.api.tasks.TaskProvider import org.gradle.api.tasks.util.PatternSet +import org.gradle.kotlin.dsl.register import org.gradle.language.base.plugins.LifecycleBasePlugin import org.jlleitschuh.gradle.ktlint.tasks.BaseKtLintCheckTask import org.jlleitschuh.gradle.ktlint.tasks.GenerateBaselineTask @@ -16,13 +17,13 @@ import org.jlleitschuh.gradle.ktlint.tasks.LoadReportersTask internal fun KtlintPlugin.PluginHolder.addGenerateReportsTaskToProjectMetaCheckTask( generatesReportsTask: TaskProvider ) { - metaKtlintCheckTask.configure { it.dependsOn(generatesReportsTask) } + metaKtlintCheckTask.configure { dependsOn(generatesReportsTask) } } internal fun KtlintPlugin.PluginHolder.addGenerateReportsTaskToProjectMetaFormatTask( generateReportsTask: TaskProvider ) { - metaKtlintFormatTask.configure { it.dependsOn(generateReportsTask) } + metaKtlintFormatTask.configure { dependsOn(generateReportsTask) } } internal fun createFormatTask( @@ -103,17 +104,16 @@ internal fun KtlintPlugin.PluginHolder.setCheckTaskDependsOnGenerateReportsTask( generateReportsTask: TaskProvider ) { target.plugins.withType(LifecycleBasePlugin::class.java) { - target.tasks.named(LifecycleBasePlugin.CHECK_TASK_NAME).configure { task -> - task.dependsOn(generateReportsTask) + target.tasks.named(LifecycleBasePlugin.CHECK_TASK_NAME) { + dependsOn(generateReportsTask) } } } internal fun createLoadReportersTask( pluginHolder: KtlintPlugin.PluginHolder -): TaskProvider = pluginHolder.target.registerTask( - LoadReportersTask.TASK_NAME -) { +): TaskProvider = + pluginHolder.target.tasks.register(LoadReportersTask.TASK_NAME) { description = LoadReportersTask.DESCRIPTION ktLintClasspath.setFrom(pluginHolder.ktlintConfiguration) @@ -130,7 +130,6 @@ private fun BaseKtLintCheckTask.configureBaseCheckTask( ) { ktLintClasspath.setFrom(pluginHolder.ktlintConfiguration) ktLintVersion.set(pluginHolder.extension.version) - additionalEditorconfigFile.set(pluginHolder.extension.additionalEditorconfigFile) additionalEditorconfig.set(pluginHolder.extension.additionalEditorconfig) debug.set(pluginHolder.extension.debug) ruleSetsClasspath.setFrom(pluginHolder.ktlintRulesetConfiguration) diff --git a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/android/AndroidPluginsApplier.kt b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/android/AndroidPluginsApplier.kt index ebf38a70..2d90a2ea 100644 --- a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/android/AndroidPluginsApplier.kt +++ b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/android/AndroidPluginsApplier.kt @@ -12,6 +12,7 @@ import com.android.build.api.variant.VariantProperties import com.android.build.gradle.internal.api.DefaultAndroidSourceDirectorySet import org.gradle.api.Plugin import org.gradle.api.file.FileCollection +import org.gradle.kotlin.dsl.findByType import org.jlleitschuh.gradle.ktlint.KtlintPlugin import org.jlleitschuh.gradle.ktlint.addGenerateReportsTaskToProjectMetaCheckTask import org.jlleitschuh.gradle.ktlint.addGenerateReportsTaskToProjectMetaFormatTask @@ -64,19 +65,19 @@ private typealias AndroidCommonExtension = CommonExtension< private fun androidPluginConfigureAction( pluginHolder: KtlintPlugin.PluginHolder ): (Plugin) -> Unit = { - pluginHolder.target.extensions.configure(CommonExtension::class.java) { ext -> - val androidCommonExtension = ext as AndroidCommonExtension + pluginHolder.target.extensions.configure(CommonExtension::class.java) { + val androidCommonExtension = this as AndroidCommonExtension - androidCommonExtension.sourceSets.all { sourceSet -> + androidCommonExtension.sourceSets.all { // https://issuetracker.google.com/u/1/issues/170650362 - val androidSourceSet = sourceSet.java as DefaultAndroidSourceDirectorySet + val androidSourceSet = java as DefaultAndroidSourceDirectorySet // Passing Callable, so returned FileCollection, will lazy evaluate it // only when task will need it. // Solves the problem of having additional source dirs in // current AndroidSourceSet, that are not available on eager // evaluation. pluginHolder.createAndroidTasks( - sourceSet.name, + name, pluginHolder.target.files(Callable { androidSourceSet.srcDirs }) ) } diff --git a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/tasks/BaseKtLintCheckTask.kt b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/tasks/BaseKtLintCheckTask.kt index 96f87e10..3b164b88 100644 --- a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/tasks/BaseKtLintCheckTask.kt +++ b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/tasks/BaseKtLintCheckTask.kt @@ -188,8 +188,6 @@ abstract class BaseKtLintCheckTask @Inject constructor( protected fun runLint( inputChanges: InputChanges ) { - checkDisabledRulesSupportedKtLintVersion() - val editorConfigUpdated = wasEditorConfigFilesUpdated(inputChanges) val filesToCheck = if (editorConfigUpdated) { source.files @@ -219,8 +217,6 @@ abstract class BaseKtLintCheckTask @Inject constructor( inputChanges: InputChanges, formatSnapshot: File ) { - checkDisabledRulesSupportedKtLintVersion() - val editorConfigUpdated = wasEditorConfigFilesUpdated(inputChanges) val filesToCheck = if (editorConfigUpdated) { source.files @@ -269,32 +265,32 @@ abstract class BaseKtLintCheckTask @Inject constructor( // Process isolation is used here to run KtLint in a separate java process. // This allows to better isolate work actions from different projects tasks between each other // and to not pollute Gradle daemon heap, which otherwise greatly increases GC time. - val queue = workerExecutor.processIsolation { spec -> - spec.classpath.from(ktLintClasspath, ruleSetsClasspath) - spec.forkOptions { options -> - options.maxHeapSize = workerMaxHeapSize.get() + val queue = workerExecutor.processIsolation { + classpath.from(ktLintClasspath, ruleSetsClasspath) + forkOptions { + maxHeapSize = workerMaxHeapSize.get() // Work around ktlint triggering reflective access errors from the embedded Kotlin // compiler. See https://youtrack.jetbrains.com/issue/KT-43704 for details. if (JavaVersion.current() >= JavaVersion.VERSION_16) { - options.jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED") + jvmArgs("--add-opens", "java.base/java.lang=ALL-UNNAMED") } } } - queue.submit(KtLintWorkAction::class.java) { params -> - params.filesToLint.from(filesToCheck) - params.enableExperimental.set(enableExperimentalRules) - params.android.set(android) - params.disabledRules.set(disabledRules) - params.debug.set(debug) - params.additionalEditorconfigFile.set(additionalEditorconfigFile) - params.additionalEditorconfig.set(additionalEditorconfig) - params.formatSource.set(formatSources) - params.discoveredErrorsFile.set(discoveredErrors) - params.ktLintVersion.set(ktLintVersion) - params.editorconfigFilesWereChanged.set(editorConfigUpdated) - params.formatSnapshot.set(formatSnapshot) + queue.submit(KtLintWorkAction::class.java) { + val task = this@BaseKtLintCheckTask + filesToLint.from(filesToCheck) + enableExperimental.set(task.enableExperimentalRules) + android.set(task.android) + disabledRules.set(task.disabledRules) + debug.set(task.debug) + additionalEditorconfig.set(task.additionalEditorconfig) + formatSource.set(formatSources) + discoveredErrorsFile.set(task.discoveredErrors) + ktLintVersion.set(task.ktLintVersion) + editorconfigFilesWereChanged.set(editorConfigUpdated) + this.formatSnapshot.set(formatSnapshot) } } @@ -315,12 +311,4 @@ abstract class BaseKtLintCheckTask @Inject constructor( } .map { it.file } .toSet() - - private fun checkDisabledRulesSupportedKtLintVersion() { - if (disabledRules.get().isNotEmpty() && - SemVer.parse(ktLintVersion.get()) < SemVer(0, 34, 2) - ) { - throw GradleException("Rules disabling is supported since 0.34.2 ktlint version.") - } - } } diff --git a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/tasks/GenerateBaselineTask.kt b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/tasks/GenerateBaselineTask.kt index 0f293246..c78641f1 100644 --- a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/tasks/GenerateBaselineTask.kt +++ b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/tasks/GenerateBaselineTask.kt @@ -1,6 +1,5 @@ package org.jlleitschuh.gradle.ktlint.tasks -import net.swiftzer.semver.SemVer import org.gradle.api.DefaultTask import org.gradle.api.Task import org.gradle.api.file.ConfigurableFileCollection @@ -50,28 +49,20 @@ abstract class GenerateBaselineTask @Inject constructor( super.onlyIf(spec) } - init { - onlyIf { - val isEnabled = SemVer.parse(ktLintVersion.get()) >= SemVer(0, 41, 0) - if (!isEnabled) logger.warn("Generate baseline only works starting from KtLint 0.41.0 version") - isEnabled - } - } - @Suppress("UnstableApiUsage") @TaskAction fun generateBaseline() { // Classloader isolation is enough here as we just want to use some classes from KtLint classpath // to get errors and generate files/console reports. No KtLint main object is initialized/used in this case. - val queue = workerExecutor.classLoaderIsolation { spec -> - spec.classpath.from(ktLintClasspath, baselineReporterClasspath) + val queue = workerExecutor.classLoaderIsolation { + classpath.from(ktLintClasspath, baselineReporterClasspath) } - - queue.submit(GenerateBaselineWorkAction::class.java) { param -> - param.discoveredErrors.setFrom(discoveredErrors) - param.ktLintVersion.set(ktLintVersion) - param.baselineFile.set(baselineFile) - param.projectDirectory.set(projectLayout.projectDirectory) + val task = this + queue.submit(GenerateBaselineWorkAction::class.java) { + discoveredErrors.setFrom(task.discoveredErrors) + ktLintVersion.set(task.ktLintVersion) + baselineFile.set(task.baselineFile) + projectDirectory.set(projectLayout.projectDirectory) } } diff --git a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/tasks/GenerateReportsTask.kt b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/tasks/GenerateReportsTask.kt index 813eab7e..c7447452 100644 --- a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/tasks/GenerateReportsTask.kt +++ b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/tasks/GenerateReportsTask.kt @@ -1,8 +1,6 @@ package org.jlleitschuh.gradle.ktlint.tasks -import net.swiftzer.semver.SemVer import org.gradle.api.DefaultTask -import org.gradle.api.GradleException import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.file.DirectoryProperty import org.gradle.api.file.ProjectLayout @@ -118,12 +116,10 @@ abstract class GenerateReportsTask @Inject constructor( @Suppress("UnstableApiUsage") @TaskAction fun generateReports() { - checkBaselineSupportedKtLintVersion() - // Classloader isolation is enough here as we just want to use some classes from KtLint classpath // to get errors and generate files/console reports. No KtLint main object is initialized/used in this case. - val queue = workerExecutor.classLoaderIsolation { spec -> - spec.classpath.from(ktLintClasspath, reportersClasspath) + val queue = workerExecutor.classLoaderIsolation { + classpath.from(ktLintClasspath, reportersClasspath) } val loadedReporters = loadLoadedReporters() @@ -131,31 +127,32 @@ abstract class GenerateReportsTask @Inject constructor( reportsOutputDirectory.file("${reportsName.get()}.${it.fileExtension}") } + val task = this loadedReporters.forEach { (loadedReporter, reporterOutput) -> - queue.submit(GenerateReportsWorkAction::class.java) { param -> - param.discoveredErrorsFile.set(discoveredErrors) - param.loadedReporterProviders.set(loadedReporterProviders) - param.reporterId.set(loadedReporter.reporterId) - param.reporterOutput.set(reporterOutput) - param.reporterOptions.set(generateReporterOptions(loadedReporter)) - param.ktLintVersion.set(ktLintVersion) - param.baseline.set(baseline) - param.projectDirectory.set(projectLayout.projectDirectory) - if (relative.get()) { - param.filePathsRelativeTo.set(project.rootDir) + queue.submit(GenerateReportsWorkAction::class.java) { + discoveredErrorsFile.set(task.discoveredErrors) + loadedReporterProviders.set(task.loadedReporterProviders) + reporterId.set(loadedReporter.reporterId) + this.reporterOutput.set(reporterOutput) + reporterOptions.set(generateReporterOptions(loadedReporter)) + ktLintVersion.set(task.ktLintVersion) + baseline.set(task.baseline) + projectDirectory.set(task.projectLayout.projectDirectory) + if (task.relative.get()) { + filePathsRelativeTo.set(project.rootDir) } } } - queue.submit(ConsoleReportWorkAction::class.java) { param -> - param.discoveredErrors.set(discoveredErrors) - param.outputToConsole.set(outputToConsole) - param.ignoreFailures.set(ignoreFailures) - param.verbose.set(verbose) - param.generatedReportsPaths.from(loadedReporters.values) - param.ktLintVersion.set(ktLintVersion) - param.baseline.set(baseline) - param.projectDirectory.set(projectLayout.projectDirectory) + queue.submit(ConsoleReportWorkAction::class.java) { + discoveredErrors.set(task.discoveredErrors) + outputToConsole.set(task.outputToConsole) + ignoreFailures.set(task.ignoreFailures) + verbose.set(task.verbose) + generatedReportsPaths.from(loadedReporters.values) + ktLintVersion.set(task.ktLintVersion) + baseline.set(task.baseline) + projectDirectory.set(projectLayout.projectDirectory) } } @@ -183,12 +180,6 @@ abstract class GenerateReportsTask @Inject constructor( return options.toMap() } - private fun checkBaselineSupportedKtLintVersion() { - if (baseline.isPresent && SemVer.parse(ktLintVersion.get()) < SemVer(0, 41, 0)) { - throw GradleException("Baseline support is only enabled for KtLint versions 0.41.0+.") - } - } - internal enum class LintType( val suffix: String ) { diff --git a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/tasks/LoadReportersTask.kt b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/tasks/LoadReportersTask.kt index 30314fb6..4f4ca497 100644 --- a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/tasks/LoadReportersTask.kt +++ b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/tasks/LoadReportersTask.kt @@ -63,22 +63,23 @@ internal abstract class LoadReportersTask @Inject constructor( // Classloader isolation is enough here as we just want to use some classes from KtLint classpath // to load reporters. No KtLint main object is initialized/used in this case. - val queue = workerExecutor.classLoaderIsolation { spec -> - spec.classpath.from(ktLintClasspath, reportersClasspath) + val queue = workerExecutor.classLoaderIsolation { + classpath.from(ktLintClasspath, reportersClasspath) } - queue.submit(LoadReportersWorkAction::class.java) { param -> - param.debug.set(debug) - param.enabledReporters.set( - enabledReporters + queue.submit(LoadReportersWorkAction::class.java) { + val task = this@LoadReportersTask + debug.set(task.debug) + enabledReporters.set( + task.enabledReporters .map { reporters -> reporters.filter { it.isAvailable() } } ) - param.customReporters.set(customReporters) - param.loadedReporters.set(loadedReporters) - param.loadedReporterProviders.set(loadedReporterProviders) - param.ktLintVersion.set(ktLintVersion) + customReporters.set(task.customReporters) + loadedReporters.set(task.loadedReporters) + loadedReporterProviders.set(task.loadedReporterProviders) + ktLintVersion.set(task.ktLintVersion) } } diff --git a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/worker/KtLintWorkAction.kt b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/worker/KtLintWorkAction.kt index 86e54a25..d0a6fc46 100644 --- a/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/worker/KtLintWorkAction.kt +++ b/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/worker/KtLintWorkAction.kt @@ -24,21 +24,11 @@ abstract class KtLintWorkAction : WorkAction() val formattedFiles = mutableMapOf() - if (parameters.additionalEditorconfigFile.isPresent && - parameters.ktLintVersion.map { SemVer.parse(it) }.get() >= SemVer(0, 47) - ) { - logger.warn("additionalEditorconfigFile no longer supported in ktlint 0.47+") - } if (parameters.additionalEditorconfig.isPresent && parameters.additionalEditorconfig.get().isNotEmpty() && parameters.ktLintVersion.map { SemVer.parse(it) }.get() < SemVer(0, 49) @@ -48,31 +38,9 @@ abstract class KtLintWorkAction : WorkAction { - ktlintInvokerFactory.initialize( - editorConfigPath = additionalEditorConfig, - - parameters.enableExperimental.getOrElse(false), - parameters.disabledRules.getOrElse(emptySet()), - - userData = userData, - debug = debug - ) - } - - is KtLintInvocation46.Factory -> { - ktlintInvokerFactory.initialize( - editorConfigPath = additionalEditorConfig, - enableExperimental = parameters.enableExperimental.getOrElse(false), - disabledRules = parameters.disabledRules.getOrElse(emptySet()), - userData = userData, - debug = debug - ) - } - is KtLintInvocation47.Factory -> { ktlintInvokerFactory.initialize( - editorConfigPath = additionalEditorConfig, + editorConfigPath = null, userData = userData, debug = debug, parameters.enableExperimental.getOrElse(false), @@ -173,7 +141,6 @@ abstract class KtLintWorkAction : WorkAction val enableExperimental: Property val debug: Property - val additionalEditorconfigFile: RegularFileProperty val additionalEditorconfig: MapProperty val formatSource: Property val discoveredErrorsFile: RegularFileProperty diff --git a/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/DisabledRulesTest.kt b/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/DisabledRulesTest.kt index 7c797317..37ce8eb4 100644 --- a/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/DisabledRulesTest.kt +++ b/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/DisabledRulesTest.kt @@ -40,13 +40,7 @@ class DisabledRulesTest : AbstractPluginTest() { "val foo = \"bar\"" ) - if (SemVer.parse(ktLintVersion) < SemVer.parse("0.34.2")) { - buildAndFail(CHECK_PARENT_TASK_NAME) { - assertThat(task(":runKtlintCheckOverMainSourceSet")?.outcome) - .`as`("Rules disabling is supported since 0.34.2 ktlint version") - .isEqualTo(TaskOutcome.FAILED) - } - } else if (SemVer.parse(ktLintVersion) < SemVer.parse("0.48.0")) { + if (SemVer.parse(ktLintVersion) < SemVer.parse("0.48.0")) { build(CHECK_PARENT_TASK_NAME) { assertThat(task(":$mainSourceSetCheckTaskName")?.outcome).isEqualTo(TaskOutcome.SUCCESS) assertThat(output).doesNotContain("Property 'ktlint_disabled_rules' is deprecated") @@ -69,8 +63,6 @@ class DisabledRulesTest : AbstractPluginTest() { @ParameterizedTest(name = "{0} with KtLint {1}: {displayName}") @ArgumentsSource(KtLintSupportedVersionsTest.SupportedKtlintVersionsProvider::class) fun lintDisabledRuleFinalNewlineEditorconfig(gradleVersion: GradleVersion, ktLintVersion: String) { - if (SemVer.parse(ktLintVersion) >= SemVer.parse("0.34.2")) { - // Rules disabling is supported since 0.34.2 ktlint version project(gradleVersion) { if (SemVer.parse(ktLintVersion) >= SemVer.parse("0.48.0")) { // new way of disabling rules introduced in 0.48 @@ -82,7 +74,7 @@ class DisabledRulesTest : AbstractPluginTest() { ktlint_standard_final-newline = disabled """.trimIndent() ) - } else if (SemVer.parse(ktLintVersion) >= SemVer.parse("0.47.0")) { + } else { // disabled rules property renamed in 0.47 (disabled_rules is still honored, but will print a warning) editorConfig.appendText( """ @@ -91,15 +83,6 @@ class DisabledRulesTest : AbstractPluginTest() { ktlint_disabled_rules = final-newline """.trimIndent() ) - } else { - editorConfig.appendText( - """ - root = true - - [*.kt] - disabled_rules = final-newline - """.trimIndent() - ) } //language=Groovy buildGradle.appendText( @@ -119,7 +102,7 @@ class DisabledRulesTest : AbstractPluginTest() { assertThat(output).doesNotContain("Property 'disabled_rules' is deprecated") } } - } + } @DisplayName("Should lint without errors when 'final-newline' and 'no-consecutive-blank-lines' are disabled") @@ -129,7 +112,7 @@ class DisabledRulesTest : AbstractPluginTest() { //language=Groovy buildGradle.appendText( """ - + ktlint.version = "0.47.1" ktlint.disabledRules = ["final-newline", "no-consecutive-blank-lines"] """.trimIndent() ) @@ -156,6 +139,10 @@ class DisabledRulesTest : AbstractPluginTest() { @CommonTest fun lintRuleDisabledInTheCode(gradleVersion: GradleVersion) { project(gradleVersion) { + //language=Groovy + buildGradle.appendText(""" + ktlint.version = "0.47.1" + """.trimIndent()) createSourceFile( "src/main/kotlin/CleanSource.kt", """ @@ -177,28 +164,4 @@ class DisabledRulesTest : AbstractPluginTest() { } } } - - @DisplayName("Should fail if KtLint version is lower then 0.34.2 and disabled rules configuration is set") - @CommonTest - fun lintShouldFailOnUnsupportedVersion(gradleVersion: GradleVersion) { - project(gradleVersion) { - //language=Groovy - buildGradle.appendText( - """ - - ktlint.version = "0.34.0" - ktlint.disabledRules = ["final-newline"] - """.trimIndent() - ) - - withCleanSources() - - buildAndFail(CHECK_PARENT_TASK_NAME) { - assertThat( - task(":${KtLintCheckTask.buildTaskNameForSourceSet("main")}")?.outcome - ).isEqualTo(TaskOutcome.FAILED) - assertThat(output).contains("Rules disabling is supported since 0.34.2 ktlint version.") - } - } - } } diff --git a/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtLintSupportedVersionsTest.kt b/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtLintSupportedVersionsTest.kt index 1d9e472e..263f3e20 100644 --- a/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtLintSupportedVersionsTest.kt +++ b/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtLintSupportedVersionsTest.kt @@ -72,39 +72,6 @@ class KtLintSupportedVersionsTest : AbstractPluginTest() { } } - @DisplayName("Lint should use editorconfig file override") - @ParameterizedTest(name = "{0} with KtLint {1}: {displayName}") - @ArgumentsSource(SupportedKtlintVersionsProvider::class) - internal fun `Lint should use editorconfig file override`( - gradleVersion: GradleVersion, - ktLintVersion: String - ) { - project(gradleVersion) { - //language=Groovy - buildGradle.appendText( - """ - - ktlint.version = "$ktLintVersion" - ktlint.additionalEditorconfigFile = project.file("${TestProject.ADDITIONAL_EDITOR_CONFIG}/.editorconfig") - """.trimIndent() - ) - withAdditionalEditorConfig() - withFailingSources() - if (SemVer.parse(ktLintVersion) >= SemVer(0, 47)) { - buildAndFail(CHECK_PARENT_TASK_NAME) { - assertThat(task(":$mainSourceSetCheckTaskName")?.outcome).isEqualTo(TaskOutcome.FAILED) - assertThat(output).contains("additionalEditorconfigFile no longer supported in ktlint 0.47+") - assertThat(output).doesNotContain("additionalEditorconfig not supported until ktlint 0.49") - } - } else { - build(CHECK_PARENT_TASK_NAME) { - assertThat(task(":$mainSourceSetCheckTaskName")?.outcome).isEqualTo(TaskOutcome.SUCCESS) - assertThat(output).doesNotContain("additionalEditorconfig not supported until ktlint 0.49") - } - } - } - } - @DisplayName("Lint should use editorconfig override (standard rule)") @ParameterizedTest(name = "{0} with KtLint {1}: {displayName}") @ArgumentsSource(SupportedKtlintVersionsProvider::class) @@ -208,25 +175,6 @@ class KtLintSupportedVersionsTest : AbstractPluginTest() { class SupportedKtlintVersionsProvider : GradleArgumentsProvider() { private val supportedKtlintVersions = mutableListOf( - "0.34.0", - "0.34.2", - "0.35.0", - "0.36.0", - "0.37.1", - "0.37.2", - "0.38.0", - "0.38.1", - "0.39.0", - "0.40.0", - "0.41.0", - "0.42.0", - "0.42.1", - // "0.43.0" does not work on JDK1.8 - // "0.43.1" asked not to use it - "0.43.2", - "0.44.0", - "0.45.2", - "0.46.1", "0.47.1", "0.48.0", "0.48.1", @@ -234,11 +182,9 @@ class KtLintSupportedVersionsTest : AbstractPluginTest() { // "0.49.0" did not expose needed baseline classes "0.49.1", "0.50.0", - "1.0.0" - ).also { - // "0.37.0" is failing on Windows machines that is fixed in the next version - if (!OS.WINDOWS.isCurrentOs) it.add("0.37.0") - } + "1.0.0", + "1.0.1" + ) override fun provideArguments( context: ExtensionContext diff --git a/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintBaselineSupportTest.kt b/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintBaselineSupportTest.kt index 43be8fed..7ad0d814 100644 --- a/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintBaselineSupportTest.kt +++ b/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintBaselineSupportTest.kt @@ -1,6 +1,5 @@ package org.jlleitschuh.gradle.ktlint -import net.swiftzer.semver.SemVer import org.assertj.core.api.Assertions.assertThat import org.gradle.testkit.runner.TaskOutcome import org.gradle.util.GradleVersion @@ -59,13 +58,12 @@ class KtlintBaselineSupportTest : AbstractPluginTest() { | | | - | - | + | | | - | - | - | + | + | + | | | | @@ -101,35 +99,10 @@ class KtlintBaselineSupportTest : AbstractPluginTest() { } } - @DisplayName("Generate baseline task should work only when KtLint version is higher then 0.41.0") - @CommonTest - fun generateBaselineMinVersion(gradleVersion: GradleVersion) { - project(gradleVersion) { - withFailingSources() - - //language=Groovy - buildGradle.appendText( - """ - - ktlint { - version.set("0.40.0") - } - """.trimIndent() - ) - - build(GenerateBaselineTask.NAME) { - assertThat(task(":${GenerateBaselineTask.NAME}")?.outcome).isEqualTo(TaskOutcome.SKIPPED) - assertThat(output).containsSequence("Generate baseline only works starting from KtLint 0.41.0 version") - } - } - } - @DisplayName("Should consider existing issues in baseline") @ParameterizedTest(name = "{0} with KtLint {1}: {displayName}") @ArgumentsSource(KtLintSupportedVersionsTest.SupportedKtlintVersionsProvider::class) fun existingIssueFilteredByBaseline(gradleVersion: GradleVersion, ktLintVersion: String) { - if (SemVer.parse(ktLintVersion) >= SemVer(0, 41, 0)) { - // baseline support was added in 0.41.0 project(gradleVersion) { //language=Groovy buildGradle.appendText( @@ -145,7 +118,7 @@ class KtlintBaselineSupportTest : AbstractPluginTest() { assertThat(task(":$mainSourceSetCheckTaskName")?.outcome).isEqualTo(TaskOutcome.SUCCESS) } } - } + } @DisplayName("Check task should still fail on file style violation that is not present in the baseline") @@ -162,30 +135,6 @@ class KtlintBaselineSupportTest : AbstractPluginTest() { } } - @DisplayName("Should fail the build if baseline file is present and ktlint version is less then 0.41.0") - @CommonTest - fun failBuildOnOldKtlintVersionsAndBaselinePresent(gradleVersion: GradleVersion) { - project(gradleVersion) { - withCleanSources() - build(GenerateBaselineTask.NAME) - - //language=Groovy - buildGradle.appendText( - """ - - ktlint { - version.set("0.40.0") - } - """.trimIndent() - ) - - buildAndFail(CHECK_PARENT_TASK_NAME) { - assertThat(task(":$mainSourceSetCheckTaskName")?.outcome).isEqualTo(TaskOutcome.FAILED) - assertThat(output).contains("Baseline support is only enabled for KtLint versions 0.41.0+.") - } - } - } - private val File.defaultBaselineFile get() = resolve("config") .resolve("ktlint") diff --git a/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintIdeaPluginTest.kt b/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintIdeaPluginTest.kt deleted file mode 100644 index 513924bb..00000000 --- a/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintIdeaPluginTest.kt +++ /dev/null @@ -1,54 +0,0 @@ -package org.jlleitschuh.gradle.ktlint - -import org.assertj.core.api.Assertions.assertThat -import org.gradle.util.GradleVersion -import org.jlleitschuh.gradle.ktlint.testdsl.TestVersions -import org.jlleitschuh.gradle.ktlint.testdsl.build -import org.jlleitschuh.gradle.ktlint.testdsl.project -import org.junit.jupiter.api.DisplayName -import org.junit.jupiter.api.Test - -class KtlintIdeaPluginTest : AbstractPluginTest() { - - @DisplayName("Applying helper plugin does not add KtLint check task") - @Test - fun applyDoesNotAddCheckTask() { - project( - GradleVersion.version(TestVersions.maxSupportedGradleVersion), - projectSetup = { - //language=Groovy - it.resolve("settings.gradle").writeText( - """ - pluginManagement { - repositories { - mavenLocal() - gradlePluginPortal() - } - - plugins { - id 'org.jetbrains.kotlin.jvm' version '${TestVersions.maxSupportedKotlinPluginVersion()}' - id 'org.jlleitschuh.gradle.ktlint-idea' version '${TestVersions.pluginVersion}' - } - } - """.trimIndent() - ) - - //language=Groovy - it.resolve("build.gradle").writeText( - """ - plugins { - id 'org.jetbrains.kotlin.jvm' - id 'org.jlleitschuh.gradle.ktlint-idea' - } - """.trimIndent() - ) - } - ) { - build(":tasks") { - assertThat(output).doesNotContain(CHECK_PARENT_TASK_NAME) - // With space to not interfere with ktlintApplyToIdeaGlobally tasks - assertThat(output).containsIgnoringCase(APPLY_TO_IDEA_TASK_NAME) - } - } - } -} diff --git a/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintPluginTest.kt b/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintPluginTest.kt index 1ff5f3ff..47253ce5 100644 --- a/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintPluginTest.kt +++ b/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintPluginTest.kt @@ -45,86 +45,6 @@ class KtlintPluginTest : AbstractPluginTest() { } } - @DisplayName("Should generate code style files in project < 0.47.0") - @CommonTest - fun generateIdeaCodeStyle(gradleVersion: GradleVersion) { - project(gradleVersion) { - buildGradle.appendText( - """ - ktlint.version = "0.46.1" - - """.trimIndent() - ) - withCleanSources() - val ideaRootDir = projectPath.resolve(".idea").apply { mkdir() } - - build(APPLY_TO_IDEA_TASK_NAME) { - assertThat(task(":$APPLY_TO_IDEA_TASK_NAME")?.outcome).isEqualTo(TaskOutcome.SUCCESS) - assertThat(ideaRootDir.listFiles()?.isNullOrEmpty()).isFalse() - } - } - } - - @DisplayName("Should not generate code style files in project >= 0.47.0") - @CommonTest - fun generateIdeaCodeStyleNew(gradleVersion: GradleVersion) { - project(gradleVersion) { - buildGradle.appendText( - """ - ktlint.version = "0.47.1" - - """.trimIndent() - ) - withCleanSources() - val ideaRootDir = projectPath.resolve(".idea").apply { mkdir() } - - build(APPLY_TO_IDEA_TASK_NAME) { - assertThat(task(":$APPLY_TO_IDEA_TASK_NAME")?.outcome).isEqualTo(TaskOutcome.SUCCESS) - assertThat(output).contains("Skipping ktlintApplyToIdea. The applyToIDEA functionality was removed from ktlint in 0.47.0.") - assertThat(ideaRootDir.listFiles()?.isNullOrEmpty()).isTrue() - } - } - } - - @DisplayName("Should generate code style file globally < 0.47.0") - @CommonTest - fun generateIdeaCodeStyleGloballyOld(gradleVersion: GradleVersion) { - project(gradleVersion) { - buildGradle.appendText( - """ - ktlint.version = "0.46.1" - - """.trimIndent() - ) - val ideaRootDir = projectPath.resolve(".idea").apply { mkdir() } - - build(APPLY_TO_IDEA_GLOBALLY_TASK_NAME) { - assertThat(task(":$APPLY_TO_IDEA_GLOBALLY_TASK_NAME")?.outcome).isEqualTo(TaskOutcome.SUCCESS) - assertThat(ideaRootDir.listFiles()?.isNullOrEmpty()).isFalse() - } - } - } - - @DisplayName("Should not generate code style file globally >= 0.47.0") - @CommonTest - fun generateIdeaCodeStyleGloballyNew(gradleVersion: GradleVersion) { - project(gradleVersion) { - buildGradle.appendText( - """ - ktlint.version = "0.47.1" - - """.trimIndent() - ) - val ideaRootDir = projectPath.resolve(".idea").apply { mkdir() } - - build(APPLY_TO_IDEA_GLOBALLY_TASK_NAME) { - assertThat(task(":$APPLY_TO_IDEA_GLOBALLY_TASK_NAME")?.outcome).isEqualTo(TaskOutcome.SUCCESS) - assertThat(output).contains("Skipping ktlintApplyToIdeaGlobally. The applyToIDEA functionality was removed from ktlint in 0.47.0.") - assertThat(ideaRootDir.listFiles()?.isNullOrEmpty()).isTrue() - } - } - } - @DisplayName("Should show only plugin meta tasks in task output") @CommonTest fun showOnlyMetaTasks(gradleVersion: GradleVersion) { @@ -137,11 +57,9 @@ class KtlintPluginTest : AbstractPluginTest() { .filter { it.startsWith("ktlint", ignoreCase = true) } .toList() - assertThat(ktlintTasks).hasSize(5) + assertThat(ktlintTasks).hasSize(3) assertThat(ktlintTasks).anyMatch { it.startsWith(CHECK_PARENT_TASK_NAME) } assertThat(ktlintTasks).anyMatch { it.startsWith(FORMAT_PARENT_TASK_NAME) } - assertThat(ktlintTasks).anyMatch { it.startsWith(APPLY_TO_IDEA_TASK_NAME) } - assertThat(ktlintTasks).anyMatch { it.startsWith(APPLY_TO_IDEA_GLOBALLY_TASK_NAME) } assertThat(ktlintTasks).anyMatch { it.startsWith(GenerateBaselineTask.NAME) } } } @@ -159,11 +77,9 @@ class KtlintPluginTest : AbstractPluginTest() { // Plus for main and test sources format and check tasks // Plus two kotlin script tasks - assertThat(ktlintTasks).hasSize(11) + assertThat(ktlintTasks).hasSize(9) assertThat(ktlintTasks).anyMatch { it.startsWith(CHECK_PARENT_TASK_NAME) } assertThat(ktlintTasks).anyMatch { it.startsWith(FORMAT_PARENT_TASK_NAME) } - assertThat(ktlintTasks).anyMatch { it.startsWith(APPLY_TO_IDEA_TASK_NAME) } - assertThat(ktlintTasks).anyMatch { it.startsWith(APPLY_TO_IDEA_GLOBALLY_TASK_NAME) } assertThat(ktlintTasks).anyMatch { it.startsWith(kotlinScriptCheckTaskName) } assertThat(ktlintTasks).anyMatch { it.startsWith( @@ -451,7 +367,7 @@ class KtlintPluginTest : AbstractPluginTest() { """ ktlint.enableExperimentalRules = true - ktlint.version = "0.34.0" + ktlint.version = "0.47.1" """.trimIndent() ) @@ -671,13 +587,13 @@ class KtlintPluginTest : AbstractPluginTest() { """ dependencies { - $KTLINT_RULESET_CONFIGURATION_NAME "com.pinterest.ktlint:ktlint-core:0.34.2" + $KTLINT_RULESET_CONFIGURATION_NAME "com.pinterest.ktlint:ktlint-cli-ruleset-core:1.0.0" } """.trimIndent() ) build(":dependencies", "--configuration", KTLINT_RULESET_CONFIGURATION_NAME) { - assertThat(output).contains("com.pinterest.ktlint:ktlint-core:0.34.2 -> 0.47.1") + assertThat(output).contains("com.pinterest.ktlint:ktlint-cli-ruleset-core:1.0.0 -> 1.0.1") } } } @@ -693,13 +609,13 @@ class KtlintPluginTest : AbstractPluginTest() { """ dependencies { - $KTLINT_REPORTER_CONFIGURATION_NAME "com.pinterest.ktlint:ktlint-core:0.34.2" + $KTLINT_REPORTER_CONFIGURATION_NAME "com.pinterest.ktlint:ktlint-cli-ruleset-core:1.0.0" } """.trimIndent() ) build(":dependencies", "--configuration", KTLINT_REPORTER_CONFIGURATION_NAME) { - assertThat(output).contains("com.pinterest.ktlint:ktlint-core:0.34.2 -> 0.47.1") + assertThat(output).contains("com.pinterest.ktlint:ktlint-cli-ruleset-core:1.0.0 -> 1.0.1") } } } diff --git a/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintPluginVersionTest.kt b/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintPluginVersionTest.kt index 7c0d0751..a169e9f0 100644 --- a/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintPluginVersionTest.kt +++ b/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/KtlintPluginVersionTest.kt @@ -28,12 +28,12 @@ class KtlintPluginVersionTest : AbstractPluginTest() { ) } - @DisplayName("Should allow to use KtLint version 0.34.0") + @DisplayName("Should allow to use KtLint version 0.47.1") @CommonTest fun allowSupportedMinimalKtLintVersion(gradleVersion: GradleVersion) { project(gradleVersion) { withCleanSources() - buildGradle.useKtlintVersion("0.34.0") + buildGradle.useKtlintVersion("0.47.1") build(CHECK_PARENT_TASK_NAME) { assertThat(task(":$mainSourceSetCheckTaskName")?.outcome).isEqualTo(TaskOutcome.SUCCESS) @@ -41,12 +41,12 @@ class KtlintPluginVersionTest : AbstractPluginTest() { } } - @DisplayName("Should fail the build on using KtLint version <0.34.0") + @DisplayName("Should fail the build on using KtLint version <0.47.0") @CommonTest fun failOnUnsupportedOldKtLintVersion(gradleVersion: GradleVersion) { project(gradleVersion) { withCleanSources() - buildGradle.useKtlintVersion("0.33.0") + buildGradle.useKtlintVersion("0.46.1") buildAndFail(CHECK_PARENT_TASK_NAME) { assertThat(task(":${LoadReportersTask.TASK_NAME}")?.outcome).isEqualTo(TaskOutcome.FAILED) } diff --git a/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/testdsl/TestAnnotations.kt b/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/testdsl/TestAnnotations.kt index 290f9bf0..e3416888 100644 --- a/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/testdsl/TestAnnotations.kt +++ b/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/testdsl/TestAnnotations.kt @@ -12,17 +12,10 @@ import kotlin.streams.asStream object TestVersions { const val minSupportedGradleVersion = KtlintBasePlugin.LOWEST_SUPPORTED_GRADLE_VERSION - const val maxSupportedGradleVersion = "8.1.1" + const val maxSupportedGradleVersion = "8.4" val pluginVersion = File("VERSION_CURRENT.txt").readText().trim() const val minSupportedKotlinPluginVersion = "1.4.32" - - fun maxSupportedKotlinPluginVersion( - gradleVersion: GradleVersion = GradleVersion.version(maxSupportedGradleVersion) - ): String = when (gradleVersion) { - in (GradleVersion.version("6.8.3")..GradleVersion.version(maxSupportedGradleVersion)) -> "1.8.10" - in (GradleVersion.version("6.7.1")..GradleVersion.version("7.1.1")) -> "1.7.21" - else -> minSupportedKotlinPluginVersion - } + const val maxSupportedKotlinPluginVersion = "1.9.10" } @Target(AnnotationTarget.FUNCTION, AnnotationTarget.CLASS) diff --git a/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/testdsl/TestDsl.kt b/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/testdsl/TestDsl.kt index a4ec48f0..2594d3ff 100644 --- a/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/testdsl/TestDsl.kt +++ b/plugin/src/test/kotlin/org/jlleitschuh/gradle/ktlint/testdsl/TestDsl.kt @@ -4,6 +4,7 @@ import org.gradle.testkit.runner.BuildResult import org.gradle.testkit.runner.GradleRunner import org.gradle.util.GradleVersion import org.jlleitschuh.gradle.ktlint.AbstractPluginTest +import org.jlleitschuh.gradle.ktlint.testdsl.TestVersions.maxSupportedKotlinPluginVersion import java.io.File fun AbstractPluginTest.project( @@ -154,14 +155,11 @@ fun TestProject.buildAndFail( fun defaultProjectSetup(gradleVersion: GradleVersion): (File) -> Unit = projectSetup("jvm", gradleVersion) -private val GradleVersion.supportedKotlinVersion - get() = TestVersions.maxSupportedKotlinPluginVersion(this) - fun projectSetup( kotlinPluginType: String, gradleVersion: GradleVersion ): (File) -> Unit = { - val kotlinPluginVersion = gradleVersion.supportedKotlinVersion + val kotlinPluginVersion = maxSupportedKotlinPluginVersion //language=Groovy it.resolve("build.gradle").writeText( """ diff --git a/settings.gradle.kts b/settings.gradle.kts index 245ec8cb..437c2612 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -24,7 +24,6 @@ pluginManagement { } } -enableFeaturePreview("VERSION_CATALOGS") enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") dependencyResolutionManagement {