【问题标题】:Kotlin compiler returning: Unresolved reference: springframework in Spring 5.0Kotlin 编译器返回:未解决的参考:Spring 5.0 中的 springframework
【发布时间】:2017-08-13 00:21:38
【问题描述】:

我正在尝试将 Kotlin 与 Spring 5.0 一起使用,但是我遇到了 Kotlin 编译器无法识别对 Spring 的任何引用的问题:

[ERROR] 未能执行目标 org.jetbrains.kotlin:kotlin-maven-plugin:1.1.1:compile (compile) on project kotlin-mvc-project:编译失败:编译失败:

[ERROR](文件位置):[7,12]未解决的参考:springframework

我正在使用 Spring 里程碑版本 Spring 5.0.0.M5 和 Kotlin 版本 1.1.1(在我的 kotlin 编译器和 IntelliJ Kotlin 插件上)。在我的任何 Kotlin 文件中,IDE 都没有突出显示编译错误,但运行 kotlin-compiler 似乎根本看不到 Spring 5.0。

有没有人知道如何解决这个问题?我在这个项目中使用 Maven,我附上了我的 POM 以供参考:

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

【问题讨论】:

  • 能否请您发布发生错误的文件部分?
  • 抱歉,不确定您指的是什么文件?在调用 mvn clean install 后运行 kotlin-compiler 时出现这些错误
  • 我现在已经设法通过回滚到 Spring 的当前发布版本来解决这个问题。 4.3.7.发布。不知道为什么我不能让 5.0 工作
  • [ERROR] (file location):[7,12] Unresolved reference: springframework 我的意思是这个错误——发生这种情况的行是什么?
  • 对了。它只是导入 org.springframework.context.annotation.Bean;代码中每个对 spring 对象的引用都会出现其中一个错误。

标签: spring maven kotlin


【解决方案1】:

在@DmitrySenkovich 帮助缩小我的 pom 不是问题后,我调查了本地 maven 存储库中可能出现的问题。我检查了 .m2 文件夹中的罐子,它们似乎有点错误并且缺少某些东西。我尝试擦除 maven repo,但它们一直被拉回原样。

这个问题出现在公司机器上,经过调查,我们的 maven settings.xml 似乎被配置为从公司范围的 Artifactory 中提取依赖项,而不是 maven Central/任何其他 repo。

依赖项应该根据需要从其他存储库中拉下到此 Arifactory 中,但无论出于何种原因(我假设是因为它们是从 maven Central 以外的存储库中拉下的),里程碑 Spring 构建的 jar 没有拉下正确。通过删除这些并手动将罐子添加到 Artifactory,我终于解决了这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-27
    • 2018-10-25
    • 1970-01-01
    • 1970-01-01
    • 2021-11-02
    • 2020-03-12
    • 2021-10-29
    • 2018-10-16
    相关资源
    最近更新 更多