gradle 프로젝트를 spring boot 프로젝트로 변경하기

jjuyaa·2022년 4월 5일
0
post-thumbnail

스프링 이니셜라이저를 사용하지 않고 스프링부트 프로젝트 시작하기

  • build.gralde 코드의 역할 알기
  • 의존성 추가 필요 시 방법

build.gralde 최상단에 buildscript 추가

gradle 7.4.2 변경 -> plugins 사용
출처 : https://docs.gradle.org/current/userguide/plugins.html

buildscripts 을 통해 spring boot로 바꾸지 않고, gradle 7.4.2 에서는 plugins 를 통해 간단하게 plugin을 적용할 수 있도록 한다.

// 아래 4개의 플러그인은 자바와 스프링 부트를 사용하기 위한 필수 플러그인들
plugins {
    id 'java'
    id 'eclipse'
    id 'org.springframework.boot' version '2.1.7.RELEASE'
    id  'io.spring.dependency-management' version "1.0.11.RELEASE"
}

이렇게 적용함해 build script 를 통한 적용보다 몇 가지 좋은 점이 있다.

  • 재사용을 높이고 여러개의 프로젝트 사이 비슷한 logic을 유지하는 overhead를 줄인다

  • 이해성과 조직성을 강화시켜 더 높은 수준의 모듈화를 가능하게 한다.

  • 반드시 필요한 로직을 캡슐화하고 build script를 최대한 명시적으로 사용할 수 있다.

  • Promotes reuse and reduces the overhead of maintaining similar logic across multiple projects

  • Allows a higher degree of modularization, enhancing comprehensibility and organization

  • Encapsulates imperative logic and allows build scripts to be as declarative as possible

--> 왜 인지는 아직 잘 모르겠다..

dependencies 추가

프로젝트 개발에 필요한 의존성들 추가하는 곳

dependencies { // 프로젝트 개발에 필요한 의존성 선언
    testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2'
    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

🔻 compile (api) VS implementation

출처 https://bluayer.com/13

  • 현재 compile은 deprecated 되었다.
기존대체
compileimplementation
testCompiletestImplmentation
debugCompiledebugImplementation
androidTestCompileandroidTestImplementation

! 기능적으로 기존 complie은 api가 대체한다.

api(complie)

  • c -> b -> a 순으로 b,c 모듈이 a 모듈을 의존하고 있다고 할 때, api의 경우 a모듈을 수정할 경우 이 모듈을 직접 혹은 간접 의존하고 있는 b,c 모듈 모두 재빌드된다.
  • 연결된 모든 모듈의 api가 노출된다.

implementation

  • c -> b -> a 순으로 b,c 모듈이 a 모듈을 의존하고 있다고 할 때, implementation의 경우 a를 직접 의존하고 있는 b만 재빌드한다.
  • 연결된 dependency가 줄어들어 변경사항이 발생해도 recompile를 적게해 빠르다.
  • api 노출이 줄어든다.

재빌드

build.gradle filedp 변경 사항이 발생할 경우 이런 버튼이 뜨고 클릭할 경우 그레이들이 변경 사항을 반영하기 시작한다.

결과는

이렇게 확인 가능!

0개의 댓글