简体   繁体   English

将java项目转换为scala项目(Intellij)

[英]Transform a java project into a scala project (Intellij)

I have a gradle project written in Java and want to turn the whole thing into a scala project (still gradle). 我有一个用Java编写的gradle项目,想把整个项目变成一个scala项目(仍然是gradle)。 Which steps are necessary to do so? 这样做需要哪些步骤?

Since java code should be fully supported in scala, this shouldn't be to hard. 由于scala中应该完全支持java代码,因此这应该不是很难。 I tried it, but I cannot write scala code within my code now. 我试过了,但我现在无法在我的代码中编写scala代码。

I started defining the main method in scala and it seems like Intellij has no idea what I try to do. 我开始在scala中定义主要方法,看起来Intellij不知道我尝试做什么。

What I did so far: 到目前为止我做了什么:

  • apply plugin: 'scala' --> in build.gradle 在build.gradle中应用插件:'scala' - >
  • compile 'org.scala-lang:scala-library:2.10.6' --> in build.gradle 在build.gradle中编译'org.scala-lang:scala-library:2.10.6' - >
  • I started a new java gradle project and moved all the packages/files over. 我启动了一个新的java gradle项目并将所有的包/文件移到了上面。
  • There is no compile error if I let the code as it is right now. 如果我现在使用代码,则没有编译错误。

Do I need to define another "project sdk"? 我需要定义另一个“项目sdk”吗?

As I understand you have issues with compiling scala code witnin new project (rec-imported). 据我所知,你有新问题编译scala代码的问题(rec-imported)。

Do you have scala-library as dependency in your project? 您是否在项目中使用scala-library作为依赖项? If not, you can add Global library to Project structure. 如果没有,您可以将全局库添加到项目结构。

First, try if it compiles in Gradle from command line ( gradle compile ). 首先,尝试从命令行( gradle compile )在Gradle中gradle compile Based on what you say, it should; 根据你的说法,它应该; if it doesn't, fix this first. 如果没有,请先修复此问题。

If it does, add Scala plugin in IDEA (if it isn't already installed) and you may need to activate Scala support explicitly as mentioned in @0__'s comment. 如果是,请在IDEA中添加Scala插件(如果尚未安装),您可能需要显式激活Scala支持,如@ 0 __的评论中所述。

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

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