Skip to content

Commit

Permalink
[WALWAL-104] Spotless 구성 (#19)
Browse files Browse the repository at this point in the history
* chore: pre-commit, spotless 구성

* chore: pre-commit 실행 모드 추가

* fix: spotlessApply

* chore: googleJavaFormat aosp

* chore: googleJavaFormat aosp

* fix: spotlessApply

* fix: spotlessApply version test

* fix: spotlessApply
  • Loading branch information
char-yb authored Jun 26, 2024
1 parent 4d775ee commit 2c31cf2
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 31 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/develop-pull-request-on-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,19 @@ jobs:
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} # required
if: always() # Pick up events even if the job fails or is canceled.

style-test:
runs-on: ubuntu-latest
steps:
- name: Git Checkout
uses: actions/checkout@v3.0.2
- name: JDK install
uses: actions/setup-java@v3
with:
distribution: zulu
java-version: '17'
cache: 'gradle'

- name: Checkstyle
run: |
./gradlew spotlessCheck
24 changes: 24 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id 'java'
id 'org.springframework.boot' version '3.2.6'
id 'io.spring.dependency-management' version '1.1.5'
id 'com.diffplug.spotless' version '6.21.0'
}

group = 'com.depromeet'
Expand Down Expand Up @@ -46,3 +47,26 @@ dependencies {
tasks.named('test') {
useJUnitPlatform()
}

spotless {
java {
target("**/*.java")
importOrder()
// 사용하지 않은 import문 제거
removeUnusedImports()
// 2개 이상 있거나 이제 앞뒤로 불필요한 공백이 있을 때 제거해주는 옵션
trimTrailingWhitespace()
// 줄은 공백으로 남아있을 수 있도록 항상 옵션을 걸어준다.
endWithNewline()
// google java format
googleJavaFormat().aosp()
}
}

// git pre-commit hook task 설정
tasks.register("addGitPreCommitHook", Copy) {
from 'scripts/pre-commit'
into '.git/hooks'
}

compileJava.dependsOn addGitPreCommitHook
13 changes: 13 additions & 0 deletions scripts/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

targetFiles=$(git diff --staged --name-only)

echo "Apply Spotless.."
./gradlew spotlessApply

# Add files to stage spotless applied
for file in $targetFiles; do
if test -f "$file"; then
git add $file
fi
done
8 changes: 3 additions & 5 deletions src/main/java/com/depromeet/stonebed/StonebedApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@

@SpringBootApplication
public class StonebedApplication {

public static void main(String[] args) {
SpringApplication.run(StonebedApplication.class, args);
}

public static void main(String[] args) {
SpringApplication.run(StonebedApplication.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,36 @@
package com.depromeet.stonebed.global.config;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;

@Configuration
public class SwaggerConfig {
private static final String PACKAGES_TO_SCAN = "com.depromeet.stonebed";
private static final String PACKAGES_TO_SCAN = "com.depromeet.stonebed";

@Value("${api.version}")
private String apiVersion;
@Value("${api.version}")
private String apiVersion;

// OpenAPI Bean 설정
@Bean
public OpenAPI openAPI() {
return new OpenAPI()
.info(new Info()
.title("WalWal 프로젝트 API 문서화")
.version(apiVersion)
.description("WalWal 프로젝트의 Swagger UI 화면입니다."));
}
// OpenAPI Bean 설정
@Bean
public OpenAPI openAPI() {
return new OpenAPI()
.info(
new Info()
.title("WalWal 프로젝트 API 문서화")
.version(apiVersion)
.description("WalWal 프로젝트의 Swagger UI 화면입니다."));
}

// GroupedOpenApi Bean 설정
@Bean
public GroupedOpenApi groupedOpenApi() {
return GroupedOpenApi.builder().group("WalWal API")
.packagesToScan(PACKAGES_TO_SCAN)
.build();
}
// GroupedOpenApi Bean 설정
@Bean
public GroupedOpenApi groupedOpenApi() {
return GroupedOpenApi.builder()
.group("WalWal API")
.packagesToScan(PACKAGES_TO_SCAN)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
@SpringBootTest
class StonebedApplicationTests {

@Test
void contextLoads() {
}

@Test
void contextLoads() {}
}

0 comments on commit 2c31cf2

Please sign in to comment.