Gradle项目报错:Task 'wrapper' not found in project ':java-gradle-demo-service'
原因可能是在创建多module项目时,Gradle把其中一个子项目当作和父项目同级来管理,因此我们只要改变它们之间的project-module关系就解决问题
Gradle创建多module项目,项目结构如下:
JDK版本:OpenJDK17, temuri-17
gradle版本:gradle-7.5-bin.zip
gradle-wrapper.properties
- distributionBase=GRADLE_USER_HOME
- distributionPath=wrapper/dists
- distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
- zipStoreBase=GRADLE_USER_HOME
- zipStorePath=wrapper/dists
settings.gradle
- rootProject.name = 'java-gradle-demo'
- include 'java-gradle-demo-api'
- include 'java-gradle-demo-service'
其他都是创建后默认, 点击Gradle窗口的刷新按钮
Reload All Gradle Project
报错如下:
解决办法如下:
1,检查Project Structure - Project Settings - Modules - 删除多余的项目java-gradle-demo-service,依次删除test、main文件夹,然后删除java-gradle-demo-service,确定,确保只保留一个parent项目 java-gradle-demo
2, 检查Project Settings - Facets,更改为下面第2幅图所示
点击Gradle窗口的刷新按钮,构建成功
BUILD SUCCESSFUL in 2s