detekt / sarif4k

Kotlin data bindings for the Static Analysis Results Interchange Format (SARIF)
Apache License 2.0
15 stars 7 forks source link

Ktlint won't compile with version 0.3.0 #61

Closed paul-dingemans closed 1 year ago

paul-dingemans commented 1 year ago

I was trying to update the sarif4k dependency in Ktlint from version 0.2.0 to 0.3.0. It however results in compilation errors below on the ktlint-cli-reporter-sarif:

> Task :ktlint-cli-reporter-sarif:compileKotlin FAILED
e: Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:
    class io.github.detekt.sarif4k.Level.Companion, unresolved supertypes: kotlinx.serialization.KSerializer
    class io.github.detekt.sarif4k.Version.Companion, unresolved supertypes: kotlinx.serialization.KSerializer
Adding -Xextended-compiler-checks argument might provide additional information.

Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath:
    class io.github.detekt.sarif4k.Level.Companion, unresolved supertypes: kotlinx.serialization.KSerializer
    class io.github.detekt.sarif4k.Version.Companion, unresolved supertypes: kotlinx.serialization.KSerializer
Adding -Xextended-compiler-checks argument might provide additional information.

Do you have any idea how to resolve?

cortinico commented 1 year ago

cc @chao2zhang

TWiStErRob commented 1 year ago
github-ktlint$ gradlew :ktlint-cli-reporter-sarif:dep > deps.txt

image

Hmm 🤔, probably the result of going multiplatform: https://github.com/detekt/sarif4k/pull/6, the weird thing is that we declare the dependency:

https://github.com/detekt/sarif4k/blob/fdd0c3a7c98ac8bb2a58e5f376bb5cdcb2c6ccef/build.gradle.kts#L34-L38

although as implementation, so it won't become part of your compileClasspath, see Runtime Dependencies at https://mvnrepository.com/artifact/io.github.detekt.sarif4k/sarif4k-jvm/0.3.0.

As a quick workaround you can add the missing dependency to ktlint-cli-reporter-sarif.

TWiStErRob commented 1 year ago

Quick decompile of sarif4k-jvm-0.3.0.jar shows:

package io.github.detekt.sarif4k;
import kotlinx.serialization.KSerializer;
import kotlinx.serialization.Serializable;

@Serializable(with = Companion.class)
public enum Level {
   public static final Companion Companion = new Companion((DefaultConstructorMarker)null);

   public static final class Companion implements KSerializer<Level> {

which means this dependency should be api.

paul-dingemans commented 1 year ago

Problem is indeed solved with 0.4. Tnx.

chao2zhang commented 1 year ago

Thank you for verifying!