Dependency between Maven and Kotlin does not result in Kotlin classes
I have two projects, one of which depends on the other. I converted the dependency project to Kotlin, but now when maven pushes the published dependency from my local maven repository, the parent project does not accept the Kotlin internal libraries needed for the dependency.
Circuit:Main Project
↳ Now-Kotlin Project
↳ Kotlin Std-lib
This throws an exception java.lang.ClassNotFoundException: kotlin.jvm.internal.Intrinsics
when starting the main project.
The Now-Kotlin project has a plugin kotlin-maven-plugin
and a kotlin-stdlib
pom.xml defined in it.
The parent project has the now-Kotlin project listed as a dependency and it is imported correctly, its classes are found and used, etc. in IntelliJ just fine.
Compiling and running the main project app on tomcat works correctly until the first code call from the now-Kotlin project, resulting in
org.apache.catalina.core.ApplicationContext log
SEVERE: StandardWrapper.Throwable
java.lang.NoClassDefFoundError: kotlin/jvm/internal/Intrinsics
....
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: kotlin.jvm.internal.Intrinsics
My guess is that the Kotlin libraries will follow the normal dependency rules for Maven and that packages org.jetbrains.kotlin
from kotlin-stdlib
will be included in the same way as any transitive dependency.
What is the correct way to include these dependencies in the main project?
Update
Main project mvn dependency:tree
relevant part:
[INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ example-core ---
[INFO] com.example:example-core:jar:1.17.0-SNAPSHOT
[INFO] +- com.example.service.search:search-client:jar:kotlin:2.0.3-SNAPSHOT:compile
POM main project
...
<dependency>
<groupId>com.example.service.search</groupId>
<artifactId>search-client</artifactId>
<version>2.0.3-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
...
New Kotlin POM project
...
<properties>
<kotlin.version>1.1.2-2</kotlin.version>
</properties>
...
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
...
<build>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
source to share
No one has answered this question yet
Check out similar questions: