5

I have two projects, one which is a dependency on the other. I've converted the dependency project over to Kotlin, but now when maven pulls the published dependency from my local maven repository the parent project is not taking in the Kotlin internal libraries that the dependency needs.

Outline:
Main Project
  ↳ Now-Kotlin Project
          ↳ Kotlin Std-lib

This results in a java.lang.ClassNotFoundException: kotlin.jvm.internal.Intrinsics exception when running the main project.

The now-Kotlin project has the kotlin-maven-plugin plugin and the kotlin-stdlib defined in it's pom.xml.

The parent project has the now-Kotlin project listed as a dependency, and it is imported correctly, it's classes found and used, etc... in IntelliJ just fine.

Compiling and startup of the main project's application on tomcat works correctly until the first invocation of code from the now-Kotlin project, which results 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 assumption is that the Kotlin libraries would follow normal dependency rules for Maven and that the org.jetbrains.kotlin packages from kotlin-stdlib would be included the same as any transitive dependency.

What is the right way to get these dependencies included into the main project?

Update

Main Project mvn dependency:tree relevant portion:

[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

Main Project POM

...
<dependency>
    <groupId>com.example.service.search</groupId>
    <artifactId>search-client</artifactId>
    <version>2.0.3-SNAPSHOT</version>
    <scope>compile</scope>
</dependency>
...

New Kotlin Project POM

...
<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>
Mejari
  • 51
  • 6
  • 1
    Your assumption about `kotlin-stdlib` dependency is correct — that's how a transitive dependency should work. You can run `mvn dependency:tree` or `mvn dependency:list` to analyze which dependencies are pulled into the main project. Also you should check what classpath is used when running the application on tomcat. – Ilya May 31 '17 at 17:44
  • Thanks for the information! Running the maven dependency check doesn't show any child dependencies off of the now-Kotlin project. If I switch the dependency on Main Project back to a non-Kotlin version of the project then `mvn dependency:tree` contains the correct child dependencies. – Mejari May 31 '17 at 22:00
  • Could you show in your question the block of pom where you add kotlin-stdlib dependency to the New-Kotlin project, and a dependency on New-Kotlin project in Main project? – Ilya Jun 01 '17 at 03:58
  • I've updated the question. – Mejari Jun 01 '17 at 17:56
  • Could it be that you just declared dependencies of New Kotlin project in the `dependencyManagement` block, but did not actually apply them in the `dependencies` top-level block? – Ilya Jun 02 '17 at 03:29
  • Throwing the kotlin-stdlib dependency into `dependencyManagement` *and* the `dependencies` top-level block in the Now-Kotlin project and the Main Project results in the same behavior. – Mejari Jun 02 '17 at 16:16

0 Answers0