java 哪个是支持“提供”方法的正确 Gradle 插件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25040445/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 07:12:04  来源:igfitidea点击:

Which is the proper Gradle plugin to support 'provided' method?

javagradlebuild.gradlelombok

提问by kapitanpattimura

I'm currently trying to include Project Lombok helper into my Gradle project, but while following their instructions for Gradlewithin my build.gradle, I'm getting the following error:

我目前正在尝试将 Project Lombok 助手包含到我的 Gradle 项目中,但是在我的 build.gradle 中按照他们的 Gradle 说明进行操作时,我收到以下错误:

Error:(11, 0) Build script error, unsupported Gradle DSL method found: 'provided()'!

错误:(11, 0) 构建脚本错误,发现不受支持的 Gradle DSL 方法:'provided()'!

Possible causes could be:

可能的原因可能是:

  • you are using Gradle version where the method is absent
  • you didn't apply Gradle plugin which provides the method
  • or there is a mistake in a build script
  • 您正在使用该方法不存在的 Gradle 版本
  • 您没有应用提供该方法的 Gradle 插件
  • 或者构建脚本中有错误

My current build.gradle file:

我当前的 build.gradle 文件:

apply plugin: 'java'

sourceCompatibility = 1.5
version = '1.0'

repositories {
    mavenCentral()
}

dependencies {
    provided "org.projectlombok:lombok:1.14.4"
    testCompile group: 'junit', name: 'junit', version: '4.11'
}

回答by endriu_l

As of release 2.12, providedscope is called compileOnly

从 2.12 版开始,provided范围被称为compileOnly



Old answer:

旧答案:

Provided scope is available in 'war' plugin (http://www.gradle.org/docs/current/userguide/war_plugin.html, providedCompile ) If You don't want to use the 'war' plugin, there is also an opened JIRA issue regarding 'provided' scope http://issues.gradle.org/browse/GRADLE-784, suggested workaround is to create Your own cofiguration:

提供的范围在'war'插件(http://www.gradle.org/docs/current/userguide/war_plugin.html,providedCompile)中可用如果你不想使用'war'插件,还有一个打开关于“提供”范围的 JIRA 问题http://issues.gradle.org/browse/GRADLE-784,建议的解决方法是创建您自己的配置:

configurations {
   provided
}

and set it to be used with your compilation classpath:

并将其设置为与您的编译类路径一起使用:

sourceSets {
    main {
        compileClasspath += configurations.provided 
    }
}

回答by mahendra chaudhary

Check your app level gradle file. If any line looks like this:

检查您的应用程序级别的 gradle 文件。如果任何一行看起来像这样:

compile dependency.gson provided dependency.javaxAnnotation

Edit it like this:

像这样编辑它:

compile dependency.gson 
provided dependency.javaxAnnotation

It should work.

它应该工作。