如何解决gradle常见问题与错误
- 错误1:
gradle项目控制台输出为乱码
# 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302
# 在gradle-wrapper.properties 添加以下内容
org.gradle.jvmargs=-Dfile.encoding=UTF-8
# 点击help->edit custom vm options 添加以下内容
-Dfile.encoding=UTF-8
# file -> settings -> Build Tools —> Gradle -> 把build and run using 和Run tests using 都改为Intelij IDEA
- 问题1
Q1:新建一个gradle项目,将其作为父工程,父工程中有src目录;在此之上新建子模块时使用spring boot快速构建,那么该子模块不会与父工程关联
A1:新建父工程或子模块都应该使用gradle构建
- 问题2
Q2:编译时报错:Spring Boot plugin requires Gradle 5 (5.6.x only) or Gradle 6 (6.3 or later). The current version is
A2:尝试修改为可以用的版本 --> 参考:https://blog.csdn.net/Rmbzz/article/details/106692188
- 问题3
Q3:编译时报错:A problem occurred evaluating root project ‘xxxxx‘.
A3:错误原因如下:
例如在父工程的build.gradle中有如下配置
// 二进制插件
plugins {
id 'java'
id 'org.springframework.boot' version '2.4.0'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
}
// 子项目的通用配置
subprojects {
// 使用插件
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
}
# 如果将plugins中的id 'org.springframework.boot' version '2.4.0'注释了,那么subprojects中的apply plugin: 'org.springframework.boot'就会找不到,导致报如上的错误
- 问题4
Q4:编译时报错:Circular dependency between the following tasks.
A4:相互依赖导致的报错
例如在父工程中引入了公共模块编译后的包
dependencies {
implementation project(':common-api')
}
而公共模块作为子模块又依赖于父工程
解决方案就是让其中一方不依赖于另一方
参考:https://blog.csdn.net/qq_32136827/article/details/109847008
- 问题5
Q5:编译时报错:[ERROR]all buildscript {} blocks must appear before any plugins {} blocks in the script
A5:buildscript块必须出现在plugins块之前
参考:https://blog.csdn.net/qq_24944303/article/details/106350033
- 问题6
Q6:gradle中某些依赖无法导入,呈灰色显示:No candidates found for method call mavenBom.
解决方案:本地安装的gradle版本确保与idea中的gradle版本一致
- gardle运行main方法报错:
finshed with non-zero wxit value 1
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。