Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin compiler returning: Unresolved reference: springframework in Spring 5.0

I'm trying to start playing around with using Kotlin together with Spring 5.0 however I am having issues with the Kotlin compiler not recognising any reference to Spring:

[ERROR] Failed to execute goal org.jetbrains.kotlin:kotlin-maven-plugin:1.1.1:compile (compile) on project kotlin-mvc-project: Compilation failure: Compilation failure:

[ERROR] (file location):[7,12] Unresolved reference: springframework

I'm using the spring milestone version Spring 5.0.0.M5 and Kotlin version 1.1.1 (on both my kotlin-compiler and IntelliJ Kotlin plugin). There are no compile errors highlighted by the IDE in any of my Kotlin files but running the kotlin-compiler it seems to not see Spring 5.0 at all.

Does anyone have any ideas how to fix this? I'm using Maven for this project, I've attached my POM for reference:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>kotlin-mvc-project</groupId>
<artifactId>kotlin-mvc-project</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
    <kotlin.version>1.1.1</kotlin.version>
    <spring.version>5.0.0.M5</spring.version>
</properties>

<repositories>
<repository>
    <id>spring-milestones</id>
    <name>Spring Milestones</name>
    <url>https://repo.spring.io/libs-milestone</url>
    <snapshots>
        <enabled>false</enabled>
    </snapshots>
</repository>
</repositories>

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

    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-compiler</artifactId>
        <version>${kotlin.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>${spring.version}</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
        <scope>provided</scope>
    </dependency>

</dependencies>

<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>


</project>
like image 650
Plog Avatar asked Mar 21 '17 11:03

Plog


1 Answers

After help from @DmitrySenkovich in narrowing down that it was not an issue with my pom I investigated what could be going wrong in my local maven repository. I checked out the jars in my .m2 folder and they seemed a bit wrong and missing certain things. I tried wiping the maven repo but they kept being pulled back the same.

This issue was on a corporate machine and after doing some investigation it seems our maven settings.xml were configured to pull down dependencies from a company wide Artifactory and not maven central/any other repo.

Dependencies are supposed to be pulled down into this Arifactory from other repositories as required but for whatever reason (I assume because they were being pulled down from a repo other than maven central) the jars for the milestone Spring builds were not pulling down correctly. By removing these and manually adding the jars to Artifactory I was able to finally resolve the issue.

like image 193
Plog Avatar answered Sep 18 '22 19:09

Plog