so scripting seems to not be able to resolve `ktor...
# scripting
n
so scripting seems to not be able to resolve
ktor-client-core
and needs the dependency to be
ktor-client-core-jvm
instead.. pretty sure that is known problem is when this is a transitive dependency, seems like using a BOM in gradle .. even in a JVM only project makes it put the
ktor-client-core
dependency into the maven pom AND the version is being omitted since it gets put into the
dependencyManagement
section in the pom file leading to idea being very confused and the script execution breaking at runtime with
java.lang.NoClassDefFoundError: io/ktor/client/HttpClientJvmKt
or similar fun errors did anyone else run into this and how did you fix it ?
👀 1
n
yes, it seems to be both the
-jvm
and that it does not look up the versions from the dependencyManagement section elsewhere in the pom file
the pomfile i am observing this on looks like this
Copy code
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="<http://maven.apache.org/POM/4.0.0>" xsi:schemaLocation="<http://maven.apache.org/POM/4.0.0> <https://maven.apache.org/xsd/maven-4.0.0.xsd>" xmlns:xsi="<http://www.w3.org/2001/XMLSchema-instance>">
  <!-- This module was also published with a richer model, Gradle metadata,  -->
  <!-- which should be used instead. Do not delete the following line which  -->
  <!-- is to indicate to Gradle or any Gradle module metadata file consumer  -->
  <!-- that they should prefer consuming it instead. -->
  <!-- do_not_remove: published-with-gradle-metadata -->
  <modelVersion>4.0.0</modelVersion>
  <groupId>io.github.typesafegithub</groupId>
  <artifactId>shared-internal</artifactId>
  <version>1.14.1-SNAPSHOT</version>
  <name>shared-internal</name>
  <description>Authoring GitHub Actions workflows in Kotlin.</description>
  <url><https://github.com/typesafegithub/github-workflows-kt></url>
  <licenses>
    <license>
      <name>Apache License, version 2.0</name>
      <url><https://www.apache.org/licenses/LICENSE-2.0.txt></url>
    </license>
  </licenses>
  <developers>
    <developer>
      <id>typesafegithub</id>
      <name>Piotr KrzemiƄski</name>
      <email>git@krzeminski.it</email>
    </developer>
  </developers>
  <scm>
    <connection>scm:git:<git://github.com/typesafegithub/github-workflows-kt.git/></connection>
    <developerConnection>scm:git:<ssh://github.com>:typesafegithub/github-workflows-kt.git</developerConnection>
    <url><https://github.com/typesafegithub/github-workflows-kt.git></url>
  </scm>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>io.ktor</groupId>
        <artifactId>ktor-bom</artifactId>
        <version>2.3.10</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.jetbrains.kotlin</groupId>
      <artifactId>kotlin-stdlib</artifactId>
      <version>1.9.23</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>io.ktor</groupId>
      <artifactId>ktor-client-core</artifactId>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>io.ktor</groupId>
      <artifactId>ktor-client-cio</artifactId>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>io.ktor</groupId>
      <artifactId>ktor-client-content-negotiation</artifactId>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>io.ktor</groupId>
      <artifactId>ktor-serialization-kotlinx-json-jvm</artifactId>
      <scope>runtime</scope>
    </dependency>
  </dependencies>
</project>
the relevant dependencies are
Copy code
implementation(platform("io.ktor:ktor-bom:2.3.10"))
    implementation("io.ktor:ktor-client-core")
    implementation("io.ktor:ktor-client-cio")
    implementation("io.ktor:ktor-client-content-negotiation")
    implementation("io.ktor:ktor-serialization-kotlinx-json-jvm")
so.. we see that we CAN fix the artifactId like i do with
ktor-serialization-kotlinx-json-jvm
(and it seems to be fine in gradle too.. at least on a jvm-only project) but the thing thats still different is the absense of a
version
in the dependencies
e
I am not sure there is anything to fix here. This is definitely WAI. Resolving the jvm variant from the common GAV is a Gradle build feature. It wont be possible without serious effort using any available (simpler) maven dependency resolvers.
n
that part is not even what breaks this though.. if I add
-jvm
to the dependencies and still use a BOM then the version tags are still missing in the XML, .. I don't think the versionManagement field in the maven pom is a gradle specific thing?
e
Yeah it depends on what maven resolver is actually used for scripts. My guess is that its a simple maven resolver that does not support the dependency management block but lets see the eventual reply on that issue
n
funny thing is that it compiles just fine?, just runs into NoClassDef errors when executing.. the first few println work just fine.. very confusing behaviour I haven't seen before
p
Aether is used there
n
wtf is Aether? a library or tool i never heard about ?
p
"Aether is a library for working with artifact repositories. Aether deals with the specification of local repository, remote repository, developer workspaces, artifact transports, and artifact resolution."
n
i see
a
(The info doesn't help with the issue here, but I thought I'd share in case it helps someone.) You can make Gradle specify the versions in the published
pom.xml
https://docs.gradle.org/8.7/userguide/publishing_maven.html#publishing_maven:resolved_dependencies I downloaded your reproducer and added
Copy code
publishing {
  publications {
    create<MavenPublication>("mavenJava") {
      // ...
      versionMapping {
        usage("java-api") {
          fromResolutionOf("runtimeClasspath")
        }
        usage("java-runtime") {
          fromResolutionResult()
        }
      }
And then published, and I could see in
.m2/repository/kt_67618/kt_67618/0.1/kt_67618-0.1.pom
it specified the versions
Copy code
<dependency>
      <groupId>io.ktor</groupId>
      <artifactId>ktor-client-core</artifactId>
      <version>2.3.10</version>
      <scope>runtime</scope>
    </dependency>
But the script still doesn't work, because Maven doesn't know that when it sees
io.ktor:ktor-client-core
it should get
io.ktor:ktor-client-core-jvm