Gradle安装依赖报错Could not find method providedCompile() gradle providedCompile、compile与runtime区别

Gradle安装依赖gradle providedCompile、compile与runtime区别

一、Gradle添加依赖报错

build.gradle文件添加依赖:

providedCompile group: 'org.projectlombok', name: 'lombok', version: '1.18.8'

在Gradle的build.gradle文件添加依赖时会碰到报错,报错信息如下:

Could not find method providedCompile() for arguments [{group=org.projectlombok, name=lombok, version=1.18.8}] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler

二、Gradle报错原因

上面添加一个依赖后,却提示报错了,经过查询发现原来是需要的插件没有添加。

这个就和添加依赖前缀 providedCompile、compile与runtime 有关系了。

build.gradle添加插件

allprojects {
    group = 'com.test'
    version = '1.0-SNAPSHOT'
    buildDir = 'target'
    apply plugin: 'java'
    apply plugin: 'war'
    apply plugin: 'idea'
    apply plugin: 'maven'

}

Complie:你的jar包或依赖代码,在编译的时候需要依赖,在运行的时候也需要,那么就用compile

使用 Complie前缀的依赖,需要在build.gradle文件中先配置 apply plugin: 'war'或者apply plugin: 'java'然后在添加依赖就不会报错了

providedCompile:你的jar包或依赖代码,仅在编译的时候需要依赖,在运行的时候不需要,那么就用providedCompile

使用providedCompile前缀的依赖,需要在build.gradle文件中先配置 apply plugin: 'war'然后在添加依赖就不会报错了

runtime:你的jar包或依赖代码,仅在运行的时候需要依赖,在编译的时候不需要,那么就用runtime

使用runtime前缀的依赖,需要在build.gradle文件中先配置 apply plugin: 'java'然后在添加依赖就不会报错了

发布了316 篇原创文章 · 获赞 117 · 访问量 42万+

猜你喜欢

转载自blog.csdn.net/m0_38039437/article/details/104702838