简体   繁体   English

Eclipse在Kotlin + Java项目中发生编译错误,但是使用Maven构建项目

[英]Compilation error in Eclipse in Kotlin + Java project, but project builds with Maven

This happens in a Java and maven project in Eclipse with a kotlin nature. 这在具有kotlin性质的Eclipse中的Java和Maven项目中发生。

In this part of the code: 在这部分代码中:

    val faces = figure.getFaces()       
    for (polygon in faces) {
        //...

I get the error below in eclipse, where faces , in the second line above, is underlined in red: 我在eclipse中得到以下错误,上面第二行中的faces用红色下划线标出:

Cannot access class 'Polygon'. Check your module classpath for missing or conflicting dependencies

The project is a mix of Java and Kotlin. 该项目混合了Java和Kotlin。 The figure object is an instance of a Java class, while the faces are a set of type Polygon which is in a different project that is pure Kotlin (ie Polygon is a Kotlin type, in a separate Kotlin project). figure对象是Java类的一个实例,而faces是一组类型为Polygon的集合,该集合位于另一个项目中,该项目是纯Kotlin(即Polygon是Kotlin类型,在单独的Kotlin项目中)。

This Kotlin project where Polygon is, is indeed in the classpath as a Maven dependency, and in fact used by the Java class of which figure is an instance. 实际上, Polygon所在的Kotlin项目实际上是作为Maven依赖项存在于类路径中,并且实际上由Java类使用,该figure是实例。

I think the problem is in Eclipse, because I can build the project with maven successfully. 我认为问题出在Eclipse中,因为我可以使用maven成功构建项目。 It looks like either a bug in eclipse or a configuration issue. 它看起来像是Eclipse中的错误或配置问题。

I know it's strange to have a mix of Java and Kotlin. 我知道Java和Kotlin的混合使用很奇怪。 I simply started this project in Java and then decided to convert it to Kotlin gradually. 我只是用Java启动了这个项目,然后决定逐步将其转换为Kotlin。 So far I haven't had many issues but I'm aware that Kotlin tools and support in eclipse are not mature yet. 到目前为止,我还没有遇到很多问题,但是我知道Eclipse的Kotlin工具和支持还不成熟。

Not much of a proper solution: I converted my Figure class to Kotlin and the problem went away, but I can do that because I have full control on my project. 没有什么合适的解决方案:我将Figure类转换为Kotlin,问题就消失了,但是我可以这样做是因为我对项目有完全的控制权。

Possibly newer versions of the eclipse plugin won't generate this error or, as suggested in the comments, switching to IntelliJ IDEA is another option. 可能是较新版本的eclipse插件不会产生此错误,或者如注释中所建议,切换到IntelliJ IDEA是另一种选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM