导入本地spring-boot-starter-web项目报错:找不到项目路径求助
解决Gradle引入本地spring-boot-starter-web项目路径找不到的问题
问题重现
在本地Spring Boot源码学习项目(:spring-boot-learn)中尝试引入:spring-boot-starter-web模块时,触发如下报错:
A problem occurred evaluating project ':spring-boot-learn'. > Project with path ':spring-boot-starter-web' could not be found in project ':spring-boot-learn'.
当前项目的build.gradle配置代码:
plugins { id 'java' } group = 'org.springframework.boot' version = '3.1.8-SNAPSHOT' repositories { mavenCentral() } dependencies { testImplementation platform('org.junit:junit-bom:5.9.1') testImplementation 'org.junit.jupiter:junit-jupiter' implementation project(':spring-boot-starter-web') } test { useJUnitPlatform() }
解决方案
检查根项目的settings.gradle配置
Gradle多模块项目必须在根项目的settings.gradle中声明所有子模块。先确认你的项目目录结构:根项目/ ├── settings.gradle ├── spring-boot-learn/ │ └── build.gradle └── spring-boot-starter-web/ └── build.gradle打开根项目的
settings.gradle,确保已包含两个模块的声明:rootProject.name = '你的根项目名称' include ':spring-boot-learn' include ':spring-boot-starter-web'如果
spring-boot-starter-web是:spring-boot-learn的子模块,依赖路径要改为implementation project(':spring-boot-learn:spring-boot-starter-web'),同时settings.gradle里要补充include ':spring-boot-learn:spring-boot-starter-web'。核对模块路径拼写
确保:spring-boot-starter-web的名称和settings.gradle里的声明完全一致,大小写、连字符等细节不能出错。同步Gradle项目
修改settings.gradle后,在IDE中点击Gradle同步按钮,让工具重新加载项目结构。确认本地模块可正常编译
先单独编译spring-boot-starter-web模块,执行命令:./gradlew :spring-boot-starter-web:build确保该模块本身无编译错误后,再在
:spring-boot-learn中引入依赖。
内容的提问来源于stack exchange,提问作者user23158449
相关产品推荐
相关产品推荐

