如何将 build.gradle 导入 IntelliJ [英] How to import build.gradle into IntelliJ

查看:28
本文介绍了如何将 build.gradle 导入 IntelliJ的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:

然后我右键单击 src/main/scala 目录,并注意到没有用于添加 Scala 源文件包的选项.或者任何 JVM(.java 等)文件:

我认为 Gradle Init 插件有缺陷(至少对于 scala-library 类型)或 Gradle IDEA 插件有缺陷.无论哪种方式,我认为我的 IntelliJ 项目文件之一中缺少某些内容:

  • IML;或
  • 知识产权;或
  • IWS

有什么想法可以更改以便 IntelliJ 显示编译器错误并添加新的 Scala 源文件吗?

解决方案

不推荐使用 gradle idea 命令生成 IntelliJ IDEA 项目文件,它会创建遗留格式的项目文件,并且在大多数情况下是项目将无法正常工作(它仅适用于基本的 Java 项目).

这种生成 IntelliJ IDEA 项目的方式已被弃用,您只需在 IntelliJ IDEA 中打开 build.gradle 文件(这与使用导入并指定构建文件位置相同).

将 Gradle 项目模型映射到 IntelliJ IDEA 项目模型确实很复杂,并且由使用 Gradle API 的 JetBrains 开发人员维护和支持,而 gradle idea 由 Gradle 开发人员添加并且不再积极维护.

NOTE: Full source code for this is here.

I used the Gradle Init plugin to create a Scala library:

gradle init --type scala-library

Then I modified its build.gradle to generate a wrapper for Gradle 2.13. Then I ran:

gradle wrapper

To generate the wrapper. And then finally I ran:

./gradlew clean idea

I opened this project in IntelliJ Community. I modified the Library.scala (that the Gradle Init plugin creates) to contain obvious Scala compiler errors, but noticed the errors weren't showing up in red underlines:

I then right-clicked the src/main/scala directory and noticed there's no options for adding packages of Scala source files. Or any JVM (.java, etc.) files for that matter:

I think either the Gradle Init plugin is flawed (for scala-library types at least) or the Gradle IDEA plugin is flawed. Either way, I think I'm missing something in one of my IntelliJ project files:

  • IML; or
  • IPR; or
  • IWS

Any ideas what I can change so that IntelliJ displays compiler errors and so that I can add new Scala source files?

解决方案

Using gradle idea command to generate IntelliJ IDEA project files is not recommended, it creates legacy format project files and in most cases the project will not work correctly (it will work only for basic Java projects).

This way of generating IntelliJ IDEA projects is deprecated and you should just open build.gradle file in IntelliJ IDEA (it's the same as using Import and specifying the build file location).

Mapping Gradle project model to IntelliJ IDEA project model is really complicated and is being maintained and supported by JetBrains developers using Gradle API, while gradle idea was added by Gradle developers and is no longer actively maintained.

这篇关于如何将 build.gradle 导入 IntelliJ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆