Gradle:找不到提供的方法()

时间:2017-08-22 04:36:34

标签: java-ee gradle ejb packaging ear

哪个是preferredprovidedprovided group,这个documented在哪里?

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 provided() 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: 2.991 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'
    provided 'javax:javaee-api:7.0'
}

参考:

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

2 个答案:

答案 0 :(得分:9)

provided插件添加war配置(您未应用),因此在您的方案中无法使用

我建议您使用gradle 2.12 +

中提供的compileOnly配置

答案 1 :(得分:1)

我不清楚,您的实际问题是什么:构建失败的原因或声明依赖项的首选方式是什么?

构建失败:据我所知,默认情况下,依赖项没有provided范围,但您可以将其声明为compileOnly,它与provided相同并且受支持Gradle自2.12版本。或者你必须使用一些额外的插件,比如spring boot插件。

或者您必须创建自定义配置以支持provided依赖项。

声明依赖关系的首选方式:providedprovided group是相同的,使用的主要是基于意见的。国际海事组织,这就是原因,你无法找到一些有关它的建议。在这两种情况下,您都声明了相同的依赖项属性,例如groupnameversion,这是唯一的区别,在一种情况下,您可以更明确地执行此操作。