Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle build file auto-formatting in Eclipse?

Eclipse Mars.

I've installed the "Minimalist" syntax highlighter editor plugin... as discussed here, but is there any way currently to get auto-formatting on .gradle files?

It may well be that there's a Groovy auto-formatting editor plugin... but that won't (I presume) do all the syntax highlighting for Gradle.

like image 559
mike rodent Avatar asked Aug 26 '16 18:08

mike rodent


1 Answers

you can use the spotless plugin for gradle to format source files as well as other types of build files including the gradle files.

If you just need something basic, you can format like this:

spotless {
    format 'misc' {
       target '*.gradle', '*.md', '.gitignore'

       trimTrailingWhitespace()
       indentWithTabs()
       endWithNewLine()
     }
}

This has the benefit of working with any IDE and you can even hook it into the build target to run automatically.

afterEvaluate {
    tasks.getByName('spotlessheck').dependsOn('spotlessApply')
}

Example with spotless 5.8.2

like image 167
Lucas Holt Avatar answered Oct 17 '22 03:10

Lucas Holt