본문 바로가기
프로젝트

Google Java Format 오류

by Dr.섭도 2024. 7. 4.

문제

 

지속적인 format 오류로 스트레스 받을 뻔 했다

제대로 이유를 찾을 수가 없어서 힘들었는데, import문에서 그 원인을 찾을 수 있었다

 

https://google.github.io/styleguide/javaguide.html

 

Google Java Style Guide

1 Introduction This document serves as the complete definition of Google's coding standards for source code in the Java™ Programming Language. A Java source file is described as being in Google Style if and only if it adheres to the rules herein. Like ot

google.github.io

 

해결

간단한 방법으로 Import 구문을 전부 지우고 위에서 아래 방향으로

차례대로 새로 Import 해왔다

그랬더니 실제로 Formatter를 통과한 모습을 보여주었다..

 

결국 Build까지 성공할 수 있었다

 

와일드 카드 사용으로 import 문을 가져와서도 안되고(import java.util.*;)

 

Ordering and spacing
Imports are ordered as follows:

All static imports in a single block.
All non-static imports in a single block.
If there are both static and non-static imports, a single blank line separates the two blocks. There are no other blank lines between import statements.

Within each block the imported names appear in ASCII sort order. (Note: this is not the same as the import statements being in ASCII sort order, since '.' sorts before ';'.)

 

이 부분을 보면 ASCII 순서로 정렬된다고 적혀있는데, 아마 내가 이것저것 넣었다 뺐다 하다보니, 순서가 얽혔나보다
일단은 그렇게 예상하고 마무리했다

 

 

혹시 아니었나 하고 domain과 entity의 순서를 바꾸어 보았는데, 해당 클래스 파일에서 바로 Problems: formatting style violations

을 뱉어냈다

 

코딩 컨벤션은 너무 어렵고 힘들게 한다..

저번 프로젝트에 FrontEnd를 맡아서 ESlint를 사용할 때에도 꽤 고통받았던 기억이 있다...

BackEnd에도 적용해 빌드하다 보니 그 때의 고통이 떠오른다...

 

혹시 정확한 이유를 알고 계신 분이 있으시다면, 댓글로 남겨주시면 감사하겠습니다.