Hello! I have an already present multiplatform pro...
# multiplatform
s
Hello! I have an already present multiplatform project which I want to a ktor server module. I have a core multiplatform module like this:
Copy code
plugins {
  kotlin("multiplatform")
  kotlin("plugin.serialization")
}

version = "1.0.0"
java.sourceCompatibility = JavaVersion.VERSION_1_8
java.targetCompatibility = JavaVersion.VERSION_1_8

kotlin {
  js(IR) {
    browser()
  }

  jvm()

  sourceSets {
    val commonMain by getting {
      dependencies {
        implementation(kotlin("stdlib-common"))
        implementation(Deps.kotlinxSerialization)
      }
    }

    val commonTest by getting {
      dependencies {
        api("org.jetbrains.kotlin:kotlin-test")
      }
    }

    val jvmMain by getting
    val jvmTest by getting
    val jsMain by getting
    val jsTest by getting
  }
}
And now I did add this new ktor module
Copy code
plugins {
  kotlin("jvm")
  kotlin("plugin.serialization")
  id("application")
}
version = "1.0.0"
java.sourceCompatibility = JavaVersion.VERSION_1_8
java.targetCompatibility = JavaVersion.VERSION_1_8

dependencies {
  implementation(kotlin("stdlib"))

  implementation(project(":core"))
  implementation("io.ktor:ktor-server-core:1.6.1")
  implementation("io.ktor:ktor-server-netty:1.6.1")
  implementation("io.ktor:ktor-serialization:1.6.1")
  implementation("ch.qos.logback:logback-classic:1.2.6")
}

application {
  mainClass.set("ca.sebleclerc.api.ApplicationKt")
}
When I execute
./gradlew server:run
I get this error:
Copy code
* What went wrong:
Could not determine the dependencies of task ':server:run'.
> Could not resolve all task dependencies for configuration ':server:runtimeClasspath'.
   > Could not resolve project :core.
     Required by:
         project :server
      > The consumer was configured to find a runtime of a library compatible with Java 8, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm'. However we cannot choose between the following variants of project :core:
          - jvmRuntimeElements
          - ktlint
        All of them match the consumer attributes:
          - Variant 'jvmRuntimeElements' capability core:1.0.0 declares a runtime of a library, packaged as a jar, preferably optimized for standard JVMs, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm':
              - Unmatched attributes:
                  - Doesn't say anything about how its dependencies are found (required its dependencies declared externally)
                  - Doesn't say anything about its target Java version (required compatibility with Java 8)
[... and so on]
I understand it can’t match anything that is produced by my core module but I can’t find anything to make it work. I did tried a few things but nothing worked… Anybody have any clue? Hint? I am using Kotlin 1.6.20-M1 Thanks for the help 🙂
s
Can you try disabling ktlint and report if this did change the situation?
s
Ok 🤔 I don’t have that error anymore … not sure what was wrong here…
s
Hmm, ktlint is creating a Gradle configuration that probably is not set up, correctly. Therefore it's interfering with Gradle's variant aware resolution. Will look into ktlint and potentially consider contributing to fix this.
You can work around by marking ktlint configurations as 'isCanBeConsumed' false
Let me know if you would like to have further help here 😊
s
Not sure where I should put
isCanBeConsumed
s
Try putting this into your root build.gradle.kts
Copy code
allprojects {
  configurations.matching { it.name == "ktlint" }.configureEach {
    isCanBeConsumed = false
  }
}
Note: this is just written from the back of my mind, not tested in any way. If this does not work, or has any unintended side effects for you, then we could jump into a Google meet call to look into the problem, if you like! ☺️
s
Wow! The snippet worked like a charm! Thanks a lot @Sebastian Sellmair [JB]! 💪 👍
p
Thanks Sebastian, saved my live when integrating a Compose Desktop App with some multiplatform classes ❤️
s
Your clue will be as good as mine 😅 I’m far from a gradle expert
And glad I could be of any help! 🙂
p
Sorry I meant the SebastiAn 😅
s
Hahahahaha no worries 🙃 my bad 🤪
p
Apparently that’s already fixed upstream https://github.com/JLLeitschuh/ktlint-gradle/issues/523 https://github.com/JLLeitschuh/ktlint-gradle/pull/571 But as the plugin is kinda abandoned it’s not released 🤷