Skip to content

Commit

Permalink
Chore: spotless 플러그인 추가 (#6)
Browse files Browse the repository at this point in the history
* Chore: spotless 플러그인 추가

* Chore: pre-commit 스크립트 추가

* Style: 기존 코드에 spotless 코드 스타일 적용

* Chore: spotless test 추가
  • Loading branch information
Jaewon-pro authored Jul 20, 2024
1 parent 41dbf8f commit c068a7d
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ jobs:
uses: gradle/actions/setup-gradle@v3

- name: Test with Gradle
run: ./gradlew clean test --stacktrace --parallel
run: ./gradlew projectTest --stacktrace --parallel
52 changes: 52 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
java
id("org.springframework.boot") version "3.3.1"
id("io.spring.dependency-management") version "1.1.5"
id("com.diffplug.spotless") version "6.25.0"
}

group = "com.dnd"
Expand Down Expand Up @@ -30,3 +31,54 @@ tasks.withType<Test> {
tasks.bootBuildImage {
createdDate = "now"
}

spotless {
encoding = Charsets.UTF_8

java {
target("**/*.java")
targetExclude("build/**", "**/*Request*.java", "**/*Response*.java", "**/*Dto*.java")
palantirJavaFormat("2.47.0")
}

java {
target("**/*.java")
endWithNewline()
indentWithSpaces(4)
trimTrailingWhitespace()
importOrder("", "java|javax", "\\#").wildcardsLast()
removeUnusedImports()
formatAnnotations()
}

format("misc") {
// define the files to apply `misc` to
target("*.gradle", "*.gradle.*", ".gitattributes", ".gitignore")

// define the steps to apply to those files
endWithNewline()
indentWithSpaces(4)
trimTrailingWhitespace()
}
}

tasks.register<Copy>("updateGitHooks") {
from("scripts/pre-commit.sh")
into(".git/hooks")
rename("pre-commit.sh", "pre-commit")
}

tasks.register<Exec>("makeGitHooksExecutable") {
commandLine("chmod", "+x", ".git/hooks/pre-commit")
dependsOn("updateGitHooks")
}

tasks.compileJava {
dependsOn("makeGitHooksExecutable")
}

tasks.register("projectTest") {
dependsOn("spotlessJavaCheck")
dependsOn("compileJava")
dependsOn("test")
}
23 changes: 23 additions & 0 deletions scripts/pre-commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh

PROJECT_ROOT=$(git rev-parse --show-toplevel)

# Part 1
stagedFiles=$(git diff --staged --name-only)

# Part 2
echo "Running spotlessApply. Formatting code..."
cd "$PROJECT_ROOT" && ./gradlew spotlessApply

# Checking the exit status
if [ $? -ne 0 ]; then
echo "Spotless apply failed!"
exit 1
fi

# Part 3
for file in $stagedFiles; do
if test -f "$file"; then
git add "$file"
fi
done
5 changes: 1 addition & 4 deletions src/test/java/com/dnd/runus/RunUsApplicationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

@SpringBootTest
class RunUsApplicationTests {

@Test
void contextLoads() {
}

void contextLoads() {}
}

0 comments on commit c068a7d

Please sign in to comment.