프로젝트 생성: Spring Initializr 대신 직접 start.spring.io 사용 및 다운그레이드

start.spring.io는 Spring Boot 프로젝트를 생성하기 위해 사용된다.

Spring Initializr가 start.spring.io를 사용을 웹 인터페이스로 제공한다.

근데 Spring Initializr가 더이상 강의영상의 스택 버젼을 지원하지 않기 때문에, 영상을 따라가기 위해서는 따로 터미널에 curl start.spring.io/starter.zip 을 사용해야 된다.

curl <https://start.spring.io/starter.zip> \
  -d type=gradle-project \
  -d language=java \
  -d bootVersion=2.7.18 \
  -d groupId=hello \
  -d artifactId=hello-spring \
  -d name=hello-spring \
  -d packageName=hello.hellospring \
  -d dependencies=web \
  -d javaVersion=11 \
  -o hello-spring.zip \
&& unzip hello-spring.zip -d hello-spring \
&& rm hello-spring.zip

근데 start.spring.io에서도 Boot 2.x를 제거했다! 그래서 우리는 일단 start.spring.io가 현재 지원하는 기본값 버젼으로 설치를 하고, 다운그레이드를 한다.

3.x 부터는 최소 요구사항이 자바 17이다. 그래서 bootVersion뿐 아니라 javaVersion을 생략한다.

설치를 한 이후에 gradle 설정 파일을 2.x, 자바 11로 바꾸고 의존모듈 설치. mavenCentral 레포에는 2.x가 남아있을테니!

curl <https://start.spring.io/starter.zip> \
  -d type=gradle-project \
  -d language=java \
  -d groupId=hello \
  -d artifactId=hello-spring \
  -d name=hello-spring \
  -d packageName=hello.hellospring \
  -d dependencies=web \
  -o hello-spring.zip
unzip hello-spring.zip -d hello-spring
rm hello-spring.zip
cd hello-spring

다운그레이드

잘 됐으면 이제 다운그레이드를 위해 build.gradle를 완전히 편집한다

cat > build.gradle << 'EOF'
plugins {
	id 'org.springframework.boot' version '2.7.18'
	id 'io.spring.dependency-management' version '1.0.15.RELEASE'
	id 'java'
}

group = 'hello'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

repositories {
	mavenCentral()
}

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
	implementation 'org.springframework.boot:spring-boot-starter-web'
	testImplementation('org.springframework.boot:spring-boot-starter-test') {
		exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
	}
}

test {
	useJUnitPlatform()
}
EOF

그리고 Gradle Wrapper도 다운그레이드 해야된다.

cat gradle/wrapper/gradle-wrapper.properties

gradle 버젼 확인. 필자의 경우 gradle-9.5.1이었다.

distributionUrlgradle-7.6.4-bin.zip 로 변경:

sed -i 's|gradle-9.5.1-bin.zip|gradle-7.6.4-bin.zip|' gradle/wrapper/gradle-wrapper.properties

준비 끝