question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

google-java-format and indentation settings

See original GitHub issue

We would like to use Google Java Format and still enforce 4 space indentation. Ideal way of doing this would be to use both googleJavaFormat("1.7") and indentWithSpaces(4) in the order and expect spotless to apply them in the given order and get the required result.

    java {
            removeUnusedImports()
            googleJavaFormat("1.7")
            indentWithSpaces(4)
            trimTrailingWhitespace()
            endWithNewline()
            paddedCell()
        }

Is there a way to enforce order of the execution of spotless to get the best of both?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
varjorantacommented, Nov 18, 2020

As this issue pops up in searches when trying to solve this for Java and Maven, I will paste the solution here as well. Similarly as said here for Gradle build:

indentWithTabs(2)
indentWithSpaces(4)

you can do the same with Maven:

    <java>
        <googleJavaFormat>
            <version>1.8</version>
            <style>GOOGLE</style>
        </googleJavaFormat>
        <indent>
            <tabs>true</tabs>
            <spacesPerTab>2</spacesPerTab>
        </indent>
        <indent>
            <spaces>true</spaces>
            <spacesPerTab>4</spacesPerTab>
        </indent>
    </java>
2reactions
jbduncancommented, Aug 1, 2019

I strongly recommend googleJavaFormat("1.7").aosp() over @nedtwigg’s solution in this case because it is the official solution. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Google IntelliJ java style: changing 2-space indentation to 4 ...
I was able to change to 4-space indentations by selecting the Android Open Source Project (AOSP) style in the google-java-format plugin ...
Read more >
Google Java Style Guide
4.2 Block indentation: +2 spaces. Each time a new block or block-like construct is opened, the indent increases by two spaces. When the...
Read more >
google-java-format - Pants build
Use AOSP style instead of Google Style (4-space indentation). ("AOSP" is the Android Open Source Project.) Advanced options ...
Read more >
platform/external/google-java-format - Git at Google
To install it, go to your IDE's settings and select the Plugins category. Click the Marketplace tab, search for the google-java-format plugin, and...
Read more >
Java formatting and linting - Visual Studio Code
After setting the formatter profile, the Format Document command will use the specific profile to format your Java files. Editing formatter settings. The ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found