폐쇄망에서 Gradle 빌드 오류 처리방법
인터넷 망에서 build.gradle 파일은
plugins {
id 'java'
id 'org.springframework.boot' version '3.4.6'
id 'io.spring.dependency-management' version '1.1.7'
}
group = 'com.incoresys'
version = '0.0.1-SNAPSHOT'
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
compileOnly name: 'lombok'
annotationProcessor name: 'lombok'
implementation fileTree(dir: 'libs', include: ['*.jar'])
}
tasks.withType(JavaCompile) {
options.compilerArgs += "-parameters"
}
이렇게 되어 있었다.
폐쇄망으로 이동하기 위해 libs 폴더 아래에 라이브러리를 다 모아 놓은 상태였다.
그리고 폐쇄망으로 옮기고 build를 하는데
The supplied phased action failed with an exception.
A problem occurred configuring root project 'xxx-project'.
Build file 'D:\Develop\workspace\xxx-project\build.gradle' line: 3
Plugin [id: 'org.springframework.boot', version: '3.4.6'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Included Builds (No included builds contain this plugin)
- Plugin Repositories (could not resolve plugin artifact 'org.springframework.boot:org.springframework.boot.gradle.plugin:3.4.6')
Searched in the following repositories:
Gradle Central Plugin Repository
Plugin [id: 'org.springframework.boot', version: '3.4.6'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Included Builds (No included builds contain this plugin)
- Plugin Repositories (could not resolve plugin artifact 'org.springframework.boot:org.springframework.boot.gradle.plugin:3.4.6')
Searched in the following repositories:
Gradle Central Plugin Repository
이런 오류가 발생했다.
우선 그래서 gradle를 offline 모드로 실행 처리 설정을 변경하였다.
이클립스 Windows > Preferences > Gradle 설정화면에서
사용중인 Gradle 경로와 JAVA 경로를 설정해 주고
Offline Mode 를 체크하고 Apply and Close 버튼을 클릭해서 offline 모드로 만들어 줬다.
그리고 [id: 'org.springframework.boot', version: '3.4.6']를 찾을 수 없다하여
spring-boot-gradle-plugin-3.4.6.jar 파일을 다운 받아서 libs 폴더로 추가하였다.
이후에 build.gradle 파일에 buildscript 항목을 추가하였다.
buildscript {
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
classpath name: 'spring-boot-gradle-plugin', version: '3.4.6'
}
}
이 부분을 넣는 이유는
Gradle이 빌드 스크립트를 실행할 때 쓸 라이브러리를 로딩하기 위해 사용하는 부분이다.
build.gradle에 보면
implementation fileTree(dir: 'libs', include: ['*.jar'])
항목이 있지만 이건 java 어플리케이션에서 쓰기위한 항목이고 buildscript는 gradle를 실행하기 위해 필요한 항목이라고 보면 된다.
그리고
plugins {
id 'java'
id 'org.springframework.boot' version '3.4.6'
id 'io.spring.dependency-management' version '1.1.7'
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}
위의 부분을 아래와 같이 수정했다.
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
apply 방식이 예전 방식이기는 하나 폐쇄망에서는 apply 방식을 써야 한다.
또한 source 컴파일 버전도 sourceCompatibility, targetCompatibility 를 사용해야 한다.
이유는 toolchain은 인터넷에서 다운로드 시도를 하기 때문이다.
이렇게 설정하고 다시 build 실행했는데 역시나,
FAILURE: Build failed with an exception.
* Where:
Build file 'D:\Temp\workspace\hwp2xml\build.gradle' line: 14
* What went wrong:
A problem occurred evaluating root project 'hwp2xml'.
> Plugin with id 'io.spring.dependency-management' not found.
이런 오류가 또 났다.
spring-dependency-management-1.1.7.jar 이 라이브러리가 필요하단다.
또 다운받아서 libs 폴더에 추가 하고
buildscript {
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
classpath name: 'spring-boot-gradle-plugin', version: '3.4.6'
classpath name: 'dependency-management-plugin', version: '1.1.7'
}
}
이렇게 추가 하고, 다시 build 실행.. 그런데 역시나 실패...
이런 저런 검색을 하면서 진행한 결과, 의존성 문제가 계속 생기는 거였다.
그래서 최종적으로 다 확인하여 생성된 buildscript는 아래와 같다.
buildscript {
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
classpath name: 'spring-boot-gradle-plugin', version: '3.4.6'
classpath name: 'spring-boot-loader-tools', version: '3.4.6'
classpath name: 'spring-boot-buildpack-platform', version: '3.4.6'
classpath name: 'dependency-management-plugin', version: '1.1.7'
// bootJar가 필요로 함
classpath name: 'commons-compress-1.27.1'
classpath name: 'commons-io-2.18.0'
classpath name: 'spring-core-6.2.7'
}
}
오래 걸렸다.
그래서 마지막으로 전체 build.gradle 내용은 다음과 같아.
buildscript {
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
classpath name: 'spring-boot-gradle-plugin', version: '3.4.6'
classpath name: 'spring-boot-loader-tools', version: '3.4.6'
classpath name: 'dependency-management-plugin', version: '1.1.7'
classpath name: 'spring-boot-buildpack-platform', version: '3.4.6'
// 🔥 bootJar가 필요로 함
classpath name: 'commons-compress-1.27.1'
classpath name: 'commons-io-2.18.0'
classpath name: 'spring-core-6.2.7'
}
}
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
group = 'com.incoresys'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
repositories {
flatDir {
dirs 'libs'
}
}
dependencies {
// 👇 lombok
compileOnly name: 'lombok'
annotationProcessor name: 'lombok'
implementation fileTree(dir: 'libs', include: ['*.jar'])
}
tasks.withType(JavaCompile) {
options.compilerArgs += "-parameters"
}