【问题标题】:How do I set the scala sdk using gradle in Idea module?如何在 Idea 模块中使用 gradle 设置 scala sdk?
【发布时间】:2017-06-06 01:32:16
【问题描述】:

我的 build.gradle 文件

idea {
    project {
        vcs {
            vcs = 'Git'
        }

        jdkName = '1.8'
        languageLevel = '1.8'
    }
}

我还想使用 gradle 在模块中设置 scala SDK。 现在,我最终不得不从 Idea UI 中的 Project Structure 手动设置它。 理想情况下,我更愿意将它设置在我的 build.gradle 文件中,这样当我运行时

渐变的想法

scala SDK 会自动为这个模块设置

【问题讨论】:

    标签: scala intellij-idea gradle ide


    【解决方案1】:

    要在 Intellij 中使用 gradle 有一个带有 scala 模块的项目,

    1. 创建一个新的IDEA based scala project
    2. 提供适当的项目名称并继续。
    3. 接下来,检查您是否在本地环境中进行了 gradle。 (使用$sudo apt install gradle安装gradle,然后使用命令$which gradle找到gradle的位置)
    4. 打开您的终端并导航到您的项目目录。执行命令$gradle init --type scala-library 这将使您的项目基于 gradle,并且您将在 Intellij 中看到相关的 gradle 文件。
    5. 重新启动 Intellij 并导航到 View > Tool Windows > Gradle 以查看 Gradle 选项卡。

    【讨论】:

      【解决方案2】:

      Gradle documentation for the Scala plugin 开始,您必须将 Scala 库依赖项添加到 compile 类路径。例如:

      compile "org.scala-lang:scala-library:2.12.4"
      compile "org.scala-lang:scala-reflect:2.12.4"
      

      要与 IntelliJ IDEA 集成,可以应用 idea 插件:

      apply plugin: 'idea'
      

      即使您的源代码仅在测试代码中,也需要将 Scala 库添加到编译类路径。之后,IntelliJ 会自动为您设置 Scala SDK。

      【讨论】:

        猜你喜欢
        • 2011-06-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-08-01
        • 2012-02-15
        • 1970-01-01
        • 1970-01-01
        • 2013-05-21
        相关资源
        最近更新 更多