상세 컨텐츠

본문 제목

[쀼] 프로젝트 설정 : pre-commit 훅으로 커밋 전에 Java format 검사 및 테스트 실행

🔥Activites/[프로젝트] 진행하며 생각을 했다

by :부셔져버린개발자 2025. 1. 1. 18:48

본문

Python 설치

pip install python

 

pre-commit 툴 설치

pip install pre-commit

 
 

프로젝트 루트 디렉토리에 .pre-commit-config.yaml 생성

  • Google Java Format 리포지토리는 .pre-commit-hooks.yaml을 제공하지 않으므로 수동 설정이 필요하다.
  • JAR 파일을 다운로드하고 실행 경로를 .pre-commit-config.yaml에 수동으로 지정한다.

 

repos:
  - repo: local
    hooks:
      - id: google-java-format
        name: google-java-format
        entry: java -jar tools/google-java-format-1.25.2-all-deps.jar
        language: system
        types: [java]
#        args: ["--replace"]
      - id: run-gradle-tests
        name: Run Gradle Tests
        entry: ./gradlew test
        language: system
        files: \.(java|gradle|groovy)$

 
 

릴리즈버전 확인 및 다운로드 (/tools에 위치)

https://github.com/google/google-java-format/releases/tag/v1.25.2

 

Release v1.25.2 · google/google-java-format

Changes: Fix a crash formatting text blocks involving trailing whitespace before the close delimiter (#1205) Full Changelog: v1.25.1...v1.25.2

github.com

 
 
 
 
 

.pre-commit-config.yaml 기반으로 pre-commit install

pre-commit install
 

 

pre-commit run

 

더보기
pre-commit clean

pre-commit install

 


pre-commit 설정에서 --replace 파일 의미 

args: ["--replace"]

자동으로 포멧 수정해줌


[Git] Git Hooks

https://git-scm.com/book/ko/v2/Git%EB%A7%9E%EC%B6%A4-Git-Hooks

 

Git - Git Hooks

여기서 한가지 알아둘 점은 저장소를 Clone 해도 클라이언트 훅은 복사되지 않는다는 점이다. 만든 정책이 반드시 적용되도록 하려면 서버 훅을 이용해야만 하며 작성은 정책 구현하기 부분을 참

git-scm.com

 

[Github] google-java-format 

https://github.com/google/google-java-format?tab=readme-ov-file

 

GitHub - google/google-java-format: Reformats Java source code to comply with Google Java Style.

Reformats Java source code to comply with Google Java Style. - google/google-java-format

github.com

 

728x90

관련글 더보기