简体   繁体   English

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

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

I'm currently trying to include Project Lombok helper into my Gradle project, but while following their instructions for Gradle within 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 您正在使用不存在该方法的Gradle版本
  • you didn't apply Gradle plugin which provides the method 您没有应用提供该方法的Gradle插件
  • or there is a mistake in a build script 或者构建脚本中存在错误

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'
}

As of release 2.12, provided scope 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,edledCompile )如果你不想使用'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 
    }
}

Check your app level gradle file. 检查您的应用级gradle文件。 If any line looks like this: 如果任何行看起来像这样:

compile dependency.gson provided dependency.javaxAnnotation

Edit it like this: 像这样编辑:

compile dependency.gson 
provided dependency.javaxAnnotation

It should work. 它应该工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM