今回は、Gradleビルド時に依存性を見つからないエラーについてみていきたいと思います。
エラー内容
Could not find org.springframework.boot:spring-boot-starter-web:.
Required by:
project :
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
org.springframework.boot:spring-boot-starter-webを見つからないことですね。
アーティファクトから提供しているリポジトリを宣言してね。ようなメッセージも出てましたね。
build.gradle
plugins {
id 'java'
}
group 'com.springboot.batch'
sourceCompatibility = '11'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
ext {
set('lombokVersion', '1.18.8')
}
dependencies {
annotationProcessor "org.projectlombok:lombok:${lombokVersion}"
implementation "org.projectlombok:lombok:${lombokVersion}"
implementation 'org.springframework.boot:spring-boot-starter-web'
}
test {
useJUnitPlatform()
}
解決
Springの依存性管理プラグインとSpringBootプラグインを設定する。(必須!)
plugins {
id 'org.springframework.boot' version '2.3.5.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
}
適用後のbuild.gradle
plugins {
id 'org.springframework.boot' version '2.3.5.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
}
group 'com.springboot.batch'
sourceCompatibility = '11'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
ext {
set('lombokVersion', '1.18.8')
}
dependencies {
annotationProcessor "org.projectlombok:lombok:${lombokVersion}"
implementation "org.projectlombok:lombok:${lombokVersion}"
implementation 'org.springframework.boot:spring-boot-starter-web'
}
test {
useJUnitPlatform()
}

ビルドも正常に動きました。
終わりに
詳しい情報は以下を参考してください。
https://github.com/spring-gradle-plugins/dependency-management-plugin
https://docs.gradle.org/current/userguide/declaring_repositories.html
