Java Intellij IDEA 和 Gradle 项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30041281/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 09:01:45  来源:igfitidea点击:

Intellij IDEA and Gradle projects

javaintellij-ideagradle

提问by benwaffle

I have a new project. Should I place apply plugin: 'idea'in build.gradleand run $ gradle idea? Or should I import the gradle project directly into IntelliJ IDEA 14.1? Which one will allow me to add dependencies to build.gradleand have IDEA automatically download & know about them?

我有一个新项目。我应该发生apply plugin: 'idea'build.gradle和运行$ gradle idea?还是应该将 gradle 项目直接导入 IntelliJ IDEA 14.1?哪一个允许我添加依赖项build.gradle并让 IDEA 自动下载并了解它们?

采纳答案by Doron Gold

With Intellij 14 you can just open the the build.gradlefile using Intellij's File --> Open. this will import the gradle project, including all dependencies. After you change something in the build.gradlefile, you can click on "refresh all gradle projects" at the top of the gradle tool window.

使用 Intellij 14,您可以build.gradle使用 Intellij 的File --> Open 打开文件。这将导入 gradle 项目,包括所有依赖项。更改build.gradle文件中的某些内容后,您可以单击 gradle 工具窗口顶部的“刷新所有 gradle 项目”。

You may also mark "use auto-import" under the Build Tools/Gradletab in Settings. This will resolve all changes made to the gradle project automatically every time you refresh your project.

您还可以在“设置”中的“构建工具/Gradle”选项卡下标记“使用自动导入” 。这将在您每次刷新项目时自动解决对 gradle 项目所做的所有更改。

The idea plugin is the old method of importing a gradle project into Intellij. With the newer versions of Intellij, it has become redundant.

idea 插件是将 gradle 项目导入 Intellij 的旧方法。使用较新版本的 Intellij,它变得多余了。

回答by HeroCC

You can create a new Gradle Project in IntelliJ, and it will handle all of the dependencies and integrate well with Gradle. You can see herefor more info and specifics.

您可以在 IntelliJ 中创建一个新的 Gradle 项目,它将处理所有依赖项并与 Gradle 很好地集成。您可以在此处查看更多信息和细节。

回答by Amnon Shochot

From my experience using the ideaplugin does not always work correctly in IntelliJ and actually IntelliJ documentation guidelinesare to simply import build.gradle file.

根据我使用idea插件的经验,在 IntelliJ 中并不总是能正常工作,实际上IntelliJ 文档指南是简单地导入 build.gradle 文件。

Also, Peter Niederwieserwho is a Principal Software Engineer at Gradlewareanswered a similar question~2 years ago mentioning the following:

此外,Gradleware首席软件工程师Peter Niederwieser大约在 2 年前回答了一个类似的问题,并提到了以下内容:

If you use Gradle's idea task to generate project files, this is normal, as there is no way to tell IDEA what the class path of the build script itself is. If you instead use IDEA's Gradle integration ("Import from Gradle model"), this problem doesn't exist.

如果使用Gradle 的idea 任务生成项目文件,这是正常的,因为没有办法告诉IDEA 构建脚本本身的类路径是什么。如果您改为使用 IDEA 的 Gradle 集成(“从 Gradle 模型导入”),则不存在此问题。

Bottom line, your safer way to go would be importing gradle project directly from IntelliJ.

最重要的是,您更安全的方法是直接从 IntelliJ 导入 gradle 项目。