简体   繁体   English

IDEA - 如何在.gradle 文件的下一行放置大括号?

[英]IDEA - How can I place braces on the next line for .gradle files?

In the Code Style settings of IntelliJ IDEA, there aren't any subcategories for .gradle files (eg, build.gradle ), and under Other File Types , there isn't any option to modify brace placements.在 IntelliJ IDEA 的Code Style设置中,没有任何.gradle文件的子类别(例如build.gradle ),并且在Other File Types下,没有任何修改大括号位置的选项。 I did not find solutions on to set brace placement for .gradle files.我没有找到为.gradle文件设置大括号位置的解决方案。

What I'm trying to do: Make the braces look like this by default and after reformatting:我正在尝试做的事情:默认情况下和重新格式化后使大括号看起来像这样:

repositories
{
    mavenCentral()
}

Instead of this:而不是这个:

repositories {
    mavenCentral()
}

Is this change possible using the current version of IntelliJ IDEA?使用当前版本的 IntelliJ IDEA 是否可以进行此更改? (2020.1.1) (2020.1.1)

Changing the code style settings for Groovy does not have an effect for some reason.由于某种原因,更改 Groovy 的代码样式设置没有效果。

在此处输入图像描述

Braces for a Groovy class is placed correctly as in the settings. Groovy class 的大括号按照设置正确放置。 (This is tested in a .gradle file.) (这是在.gradle文件中测试的。)

在此处输入图像描述

It looks like the Settings (Preferences on macOS) → EditorCode StyleGroovyWrapping and BracesBraces placement → * Other option does not work as expected.看起来设置(macOS 上的首选项)→编辑器代码样式Groovy包装和大括号大括号放置→ *其他选项无法按预期工作。

Please vote for the issue IDEA-241366 .请为IDEA-241366问题投票。

.gradle files are actually Groovy files. .gradle文件实际上是 Groovy 文件。 You can check that by looking under EditorFile TypesGroovy .您可以通过查看EditorFile TypesGroovy来检查。

As such, you can modify the code style for Groovy to move braces onto the next line by going under EditorCode StyleGroovyWrapping and Braces tab → Braces placement and tweaking it to your liking.因此,您可以修改 Groovy 的代码样式以将大括号移动到下一行,方法是在编辑器代码样式Groovy包装和大括号选项卡 →大括号放置并根据自己的喜好进行调整。

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

相关问题 如何使用Gradle下载依赖项及其源文件并将它们全部放置在一个目录中? - How can I use Gradle to download dependencies and their source files and place them all in one directory? IntelliJ IDEA + Gradle-如何记录从IDE运行的长时间运行的Gradle任务? - IntelliJ IDEA + Gradle - How can I log a long running Gradle task run from the IDE? 在 IntelliJ IDEA 中找不到“Sync Project with Gradle Files”按钮 - Can't find “Sync Project with Gradle Files” button in IntelliJ IDEA 如何使用gradle idea任务设置Intellij的默认设置? - How can I use the gradle idea task to set Intellij's default settings? 如何在Gradle项目中使用IntelliJ IDEA生成包含javadoc的.jar? - How can I generate a .jar that also includes javadoc in it using IntelliJ IDEA in a Gradle project? 如何从命令行将 VM arguments 传递给 gradle? - How can I pass VM arguments to gradle from command line? 如何在命令行上构建没有 Gradle 的 Android apk? - How can I build an Android apk without Gradle on the command line? 如何从命令行向 gradle 询问属性的值? - How can I ask gradle for the value of a property from the command line? 我可以在不导入IDEA的情况下获得gradle支持吗? - Can I have gradle support in IDEA without importing it? 如何从文件列表中创建gradle的zip? - How can I create a zip in gradle from a list of files?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM