【问题标题】:Gradle: Could not find method providedCompile()Gradle:找不到方法providedCompile()
【发布时间】:2018-01-30 05:29:20
【问题描述】:

thisthis 构建文件如何使用providedCompile

thufir@doge:~/NetBeansProjects/gradleEAR$ 
thufir@doge:~/NetBeansProjects/gradleEAR$ gradle clean

FAILURE: Build failed with an exception.

* Where:
Build file '/home/thufir/NetBeansProjects/gradleEAR/build.gradle' line: 40

* What went wrong:
A problem occurred evaluating root project 'gradleEAR'.
> Could not find method providedCompile() for arguments [javax:javaee-api:7.0] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 12.721 secs
thufir@doge:~/NetBeansProjects/gradleEAR$ 

plugins {
    id 'com.gradle.build-scan' version '1.8' 
    id 'java'
    id 'application'
    id 'ear'
}

mainClassName = 'net.bounceme.doge.json.Main'

buildScan {
    licenseAgreementUrl = 'https://gradle.com/terms-of-service'
    licenseAgree = 'yes'
}

repositories {
    jcenter()
}

jar {
    manifest {
        attributes 'Main-Class': 'net.bounceme.doge.json.Main'
    }
}

task fatJar(type: Jar) {
    baseName = project.name + '-all'
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
    manifest {
        attributes 'Implementation-Title': 'Gradle Quickstart', 'Implementation-Version': '3.4.0'
        attributes 'Main-Class': 'net.bounceme.doge.json.Main'
    }
}

dependencies {
    compile group: 'javax.json', name: 'javax.json-api', version: '1.1'
    compile group: 'org.glassfish', name: 'javax.json', version: '1.1'
    providedCompile 'javax:javaee-api:7.0'
}

参考:

How does Gradle resolve the javaee-api dependency to build an EAR?

【问题讨论】:

    标签: jakarta-ee gradle build ejb ear


    【解决方案1】:

    providedCompile 附带war 插件。所以你需要添加:

    plugins {
      // ...
      id 'war'
    }
    

    【讨论】:

    • 在我的情况下,我应用了战争,但它仍然给我同样的错误。
    • 应该在哪里添加?
    • @PabloPazos,你的构建脚本的开始。
    【解决方案2】:

    如果您安装了更高版本的 Gradle,您可能会收到此错误。例如你有:

    gradle --version
    

    给予

    Gradle 5.0
    

    但该项目需要 Gradle 2.10 或其他一些较低版本的 Gradle。

    要解决这个问题,首先尝试使用 Gradle 包装器./gradlew(如果包含在项目中)而不是本地安装的 gradle。或者安装正确版本的 gradle 并使用路径变量使其可用。

    【讨论】:

    • 按项目,您是指我将从事的具体项目?
    • 是的。假设项目是由其他人创建的。
    猜你喜欢
    • 2017-03-16
    • 2015-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-21
    • 2015-11-19
    • 2017-10-27
    • 2015-03-29
    相关资源
    最近更新 更多