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

WIP: Make KtLint tasks runnable even without specific plugins being present #426

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

realdadfish
Copy link
Contributor

@realdadfish realdadfish commented Dec 13, 2024

Should fix #423, however, when integrated in my codebase I now get a transitive dependency issue:

Caused by: java.lang.NoClassDefFoundError: io/github/oshai/kotlinlogging/KotlinLogging
        at com.pinterest.ktlint.ruleset.standard.rules.WrappingRuleKt.<clinit>(WrappingRule.kt:90)
        at com.pinterest.ktlint.ruleset.standard.rules.ArgumentListWrappingRule.<init>(ArgumentListWrappingRule.kt:72)
        at com.pinterest.ktlint.ruleset.standard.StandardRuleSetProvider.getRuleProviders$lambda$2(StandardRuleSetProvider.kt:110)
        at com.pinterest.ktlint.rule.engine.core.api.RuleProvider$Companion.invoke(RuleProvider.kt:41)
        at com.pinterest.ktlint.ruleset.standard.StandardRuleSetProvider.getRuleProviders(StandardRuleSetProvider.kt:110)
        at org.jmailen.gradle.kotlinter.support.RuleSetsKt$resolveRuleProviders$2.invoke(RuleSets.kt:17)
        at org.jmailen.gradle.kotlinter.support.RuleSetsKt$resolveRuleProviders$2.invoke(RuleSets.kt:17)
        at kotlin.sequences.FlatteningSequence$iterator$1.ensureItemIterator(Sequences.kt:330)
        at kotlin.sequences.FlatteningSequence$iterator$1.hasNext(Sequences.kt:318)
        at kotlin.sequences.SequencesKt___SequencesKt.toSet(_Sequences.kt:842)
        at org.jmailen.gradle.kotlinter.support.RuleSetsKt.resolveRuleProviders(RuleSets.kt:19)
        at org.jmailen.gradle.kotlinter.support.KtlintEngineUtilsKt.<clinit>(KtlintEngineUtils.kt:9)
        at org.jmailen.gradle.kotlinter.tasks.format.FormatWorkerAction.execute(FormatWorkerAction.kt:24)
        at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:63)
        at org.gradle.workers.internal.AbstractClassLoaderWorker$1.create(AbstractClassLoaderWorker.java:54)
        at org.gradle.workers.internal.AbstractClassLoaderWorker$1.create(AbstractClassLoaderWorker.java:48)
        at org.gradle.internal.classloader.ClassLoaderUtils.executeInClassloader(ClassLoaderUtils.java:100)
        at org.gradle.workers.internal.AbstractClassLoaderWorker.executeInClassLoader(AbstractClassLoaderWorker.java:48)
        at org.gradle.workers.internal.IsolatedClassloaderWorker.run(IsolatedClassloaderWorker.java:49)
        at org.gradle.workers.internal.IsolatedClassloaderWorker.run(IsolatedClassloaderWorker.java:30)
        at org.gradle.workers.internal.WorkerDaemonServer.run(WorkerDaemonServer.java:103)
        at org.gradle.workers.internal.WorkerDaemonServer.run(WorkerDaemonServer.java:72)
        at org.gradle.process.internal.worker.request.WorkerAction$1.call(WorkerAction.java:152)
        at org.gradle.process.internal.worker.child.WorkerLogEventListener.withWorkerLoggingProtocol(WorkerLogEventListener.java:41)
        at org.gradle.process.internal.worker.request.WorkerAction.lambda$run$1(WorkerAction.java:149)
        at org.gradle.internal.operations.CurrentBuildOperationRef.with(CurrentBuildOperationRef.java:85)
        at org.gradle.process.internal.worker.request.WorkerAction.run(WorkerAction.java:141)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
        at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
        at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:182)
        at org.gradle.internal.remote.internal.hub.MessageHubBackedObjectConnection$DispatchWrapper.dispatch(MessageHubBackedObjectConnection.java:164)
        at org.gradle.internal.remote.internal.hub.MessageHub$Handler.run(MessageHub.java:414)
        at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
        at org.gradle.internal.concurrent.AbstractManagedExecutor$1.run(AbstractManagedExecutor.java:48)
Caused by: java.lang.ClassNotFoundException: io.github.oshai.kotlinlogging.KotlinLogging
        ... 37 more

Configuration:

import org.jmailen.gradle.kotlinter.tasks.FormatTask

plugins {
    id("org.jmailen.kotlinter")
}

configureKotlinter()

tasks.register("formatKotlinSources", FormatTask::class.java) {
    description = "Formats specific Kotlin source files"
    group = "Formatting"
    ktlintClasspath.from()
    source(files(providers.systemProperty("kotlin.files").map { it.split(",") }))
}

fun Project.configureKotlinter() {
    configure<KotlinterExtension> {
        ktlintVersion = "1.5.0"
        ignoreFormatFailures = true
        ignoreLintFailures = false
        reporters = arrayOf("plain", "checkstyle")
    }
}

@realdadfish
Copy link
Contributor Author

Interestingly, the lib in question (io.github.oshai:kotlin-logging-jvm) is pulled:

$ gradle :dependencies
> Task :dependencies

------------------------------------------------------------
Root project 'android-monorepo'
------------------------------------------------------------

ktlint
\--- com.pinterest.ktlint:ktlint-cli:1.5.0
     +--- com.pinterest.ktlint:ktlint-logger:1.5.0
     |    +--- dev.drewhamilton.poko:poko-annotations:0.18.0
     |    |    \--- dev.drewhamilton.poko:poko-annotations-jvm:0.18.0
     |    +--- io.github.oshai:kotlin-logging-jvm:7.0.3
     |    \--- org.jetbrains.kotlin:kotlin-stdlib:2.1.0
     |         \--- org.jetbrains:annotations:13.0
     +--- com.pinterest.ktlint:ktlint-cli-reporter-baseline:1.5.0
     |    +--- com.pinterest.ktlint:ktlint-logger:1.5.0 (*)
     |    +--- com.pinterest.ktlint:ktlint-rule-engine-core:1.5.0
     |    |    +--- com.pinterest.ktlint:ktlint-logger:1.5.0 (*)
     |    |    +--- dev.drewhamilton.poko:poko-annotations:0.18.0 (*)
     |    |    +--- org.jetbrains.kotlin:kotlin-compiler-embeddable:2.1.0
     |    |    |    +--- org.jetbrains.kotlin:kotlin-stdlib:2.1.0 (*)
     |    |    |    +--- org.jetbrains.kotlin:kotlin-script-runtime:2.1.0
     |    |    |    +--- org.jetbrains.kotlin:kotlin-reflect:1.6.10
     |    |    |    +--- org.jetbrains.kotlin:kotlin-daemon-embeddable:2.1.0
     |    |    |    +--- org.jetbrains.intellij.deps:trove4j:1.0.20200330
     |    |    |    \--- org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4
     |    |    +--- org.ec4j.core:ec4j-core:1.1.0
     |    |    \--- org.jetbrains.kotlin:kotlin-stdlib:2.1.0 (*)
     |    +--- com.pinterest.ktlint:ktlint-cli-reporter-core:1.5.0
     |    |    +--- dev.drewhamilton.poko:poko-annotations:0.18.0 (*)
     |    |    \--- org.jetbrains.kotlin:kotlin-stdlib:2.1.0 (*)
     |    +--- dev.drewhamilton.poko:poko-annotations:0.18.0 (*)
     |    \--- org.jetbrains.kotlin:kotlin-stdlib:2.1.0 (*)
     +--- com.pinterest.ktlint:ktlint-cli-reporter-core:1.5.0 (*)
     +--- com.pinterest.ktlint:ktlint-cli-reporter-plain:1.5.0
     |    +--- com.pinterest.ktlint:ktlint-cli-reporter-core:1.5.0 (*)
     |    +--- dev.drewhamilton.poko:poko-annotations:0.18.0 (*)
     |    \--- org.jetbrains.kotlin:kotlin-stdlib:2.1.0 (*)
     +--- com.pinterest.ktlint:ktlint-rule-engine:1.5.0
     |    +--- com.pinterest.ktlint:ktlint-logger:1.5.0 (*)
     |    +--- dev.drewhamilton.poko:poko-annotations:0.18.0 (*)
     |    +--- com.pinterest.ktlint:ktlint-rule-engine-core:1.5.0 (*)
     |    +--- org.jetbrains.kotlin:kotlin-compiler-embeddable:2.1.0 (*)
     |    +--- org.ec4j.core:ec4j-core:1.1.0
     |    \--- org.jetbrains.kotlin:kotlin-stdlib:2.1.0 (*)
     +--- com.pinterest.ktlint:ktlint-ruleset-standard:1.5.0
     |    +--- com.pinterest.ktlint:ktlint-logger:1.5.0 (*)
     |    +--- dev.drewhamilton.poko:poko-annotations:0.18.0 (*)
     |    +--- com.pinterest.ktlint:ktlint-cli-ruleset-core:1.5.0
     |    |    +--- dev.drewhamilton.poko:poko-annotations:0.18.0 (*)
     |    |    +--- com.pinterest.ktlint:ktlint-rule-engine-core:1.5.0 (*)
     |    |    \--- org.jetbrains.kotlin:kotlin-stdlib:2.1.0 (*)
     |    +--- com.pinterest.ktlint:ktlint-rule-engine-core:1.5.0 (*)
     |    \--- org.jetbrains.kotlin:kotlin-stdlib:2.1.0 (*)
     +--- com.github.ajalt.clikt:clikt:5.0.2
     |    \--- com.github.ajalt.clikt:clikt-jvm:5.0.2
     +--- ch.qos.logback:logback-classic:1.3.14
     |    +--- ch.qos.logback:logback-core:1.3.14
     |    \--- org.slf4j:slf4j-api:2.0.7
     +--- dev.drewhamilton.poko:poko-annotations:0.18.0 (*)
     +--- org.jetbrains.kotlin:kotlin-stdlib:2.1.0 (*)
     +--- com.pinterest.ktlint:ktlint-cli-reporter-checkstyle:1.5.0
     |    +--- com.pinterest.ktlint:ktlint-cli-reporter-core:1.5.0 (*)
     |    +--- dev.drewhamilton.poko:poko-annotations:0.18.0 (*)
     |    \--- org.jetbrains.kotlin:kotlin-stdlib:2.1.0 (*)
     +--- com.pinterest.ktlint:ktlint-cli-reporter-json:1.5.0
     |    +--- com.pinterest.ktlint:ktlint-cli-reporter-core:1.5.0 (*)
     |    +--- dev.drewhamilton.poko:poko-annotations:0.18.0 (*)
     |    \--- org.jetbrains.kotlin:kotlin-stdlib:2.1.0 (*)
     +--- com.pinterest.ktlint:ktlint-cli-reporter-format:1.5.0
     |    +--- com.pinterest.ktlint:ktlint-cli-reporter-core:1.5.0 (*)
     |    +--- dev.drewhamilton.poko:poko-annotations:0.18.0 (*)
     |    \--- org.jetbrains.kotlin:kotlin-stdlib:2.1.0 (*)
     +--- com.pinterest.ktlint:ktlint-cli-reporter-html:1.5.0
     |    +--- com.pinterest.ktlint:ktlint-cli-reporter-core:1.5.0 (*)
     |    +--- dev.drewhamilton.poko:poko-annotations:0.18.0 (*)
     |    \--- org.jetbrains.kotlin:kotlin-stdlib:2.1.0 (*)
     +--- com.pinterest.ktlint:ktlint-cli-reporter-plain-summary:1.5.0
     |    +--- com.pinterest.ktlint:ktlint-cli-reporter-core:1.5.0 (*)
     |    +--- dev.drewhamilton.poko:poko-annotations:0.18.0 (*)
     |    \--- org.jetbrains.kotlin:kotlin-stdlib:2.1.0 (*)
     \--- com.pinterest.ktlint:ktlint-cli-reporter-sarif:1.5.0
          +--- com.pinterest.ktlint:ktlint-cli-reporter-core:1.5.0 (*)
          +--- io.github.detekt.sarif4k:sarif4k:0.6.0
          |    \--- io.github.detekt.sarif4k:sarif4k-jvm:0.6.0
          +--- dev.drewhamilton.poko:poko-annotations:0.18.0 (*)
          \--- org.jetbrains.kotlin:kotlin-stdlib:2.1.0 (*)

(*) - Indicates repeated occurrences of a transitive dependency subtree. Gradle expands transitive dependency subtrees only once per project; repeat occurrences only display the root of the subtree, followed by this annotation.

A web-based, searchable dependency report is available by adding the --scan option.

BUILD SUCCESSFUL in 952ms
23 actionable tasks: 1 executed, 22 up-to-date
Configuration cache entry stored.

@jeremymailen
Copy link
Owner

Thanks, I think this is the right conceptual fix. I overlooked this detail in my hasty fix.

I get the same error on a local project.
I think the issue might be in the order of apply? The standard plugin source sets might not be created yet by the time the code runs to configure them?

@jeremymailen jeremymailen self-requested a review December 17, 2024 05:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Kotlinter 5.0.0 java.lang.NoClassDefFoundError: com/pinterest/ktlint/rule/engine/api/KtLintRuleEngine
2 participants