Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven with Kotlin 1.2 : A required class was missing kotlin/reflect/KDeclarationContainer

Tags:

java

maven

kotlin

I tried to use Kotlin with Maven so I followed the documentation

I have this configuration in the pom.xml file

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <kotlin.version>1.2.10</kotlin.version>
</properties>

<build>
    <sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
    <testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
    <plugins>
        <plugin>
            <artifactId>kotlin-maven-plugin</artifactId>
            <groupId>org.jetbrains.kotlin</groupId>
            <version>${kotlin.version}</version>

            <executions>
                <execution>
                    <id>compile</id>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>

                <execution>
                    <id>test-compile</id>
                    <goals>
                        <goal>test-compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-stdlib-jdk8</artifactId>
        <version>${kotlin.version}</version>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-reflect</artifactId>
        <version>${kotlin.version}</version>
    </dependency>
</dependencies>

The sources folders are src/main/kotlin and src/test/kotlin

When I do mvn clean install I got this error

[ERROR] Failed to execute goal org.jetbrains.kotlin:kotlin-maven-plugin:1.2.10:compile (compile) on project kotlin-starter: Execution compile of goal org.jetbrains.kotlin:kotlin-maven-plugin:1.2.10:compile failed: A required class was missing while executing org.jetbrains.kotlin:kotlin-maven-plugin:1.2.10:compile: kotlin/reflect/KDeclarationContainer
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>org.jetbrains.kotlin:kotlin-maven-plugin:1.2.10
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
...

I also tried using kotlin-stdlib instead of kotlin-stdlib-jdk8 but I got the same error. When I open the library I see the classKDeclarationContainer in the package kotlin.reflect so I don't understand why I got this error ?

EDIT : when I change kotlin version to <kotlin.version>1.1.61</kotlin.version>, everything works perfectly...

like image 277
Olivier Boissé Avatar asked Dec 19 '17 14:12

Olivier Boissé


1 Answers

I had a very similar issue with kotlin-maven-plugin/1.2.20 which went away after I deleted org/jetbrains out of my local maven repo and re-ran the build. I can only think something was corrupted or missing.

like image 91
swiss_steve Avatar answered Oct 26 '22 09:10

swiss_steve