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

Maven Gradle:找不到提供的方法()(组),maven,jakarta-ee,gradle,ejb,ear,Maven,Jakarta Ee,Gradle,Ejb,Ear,如果这是Maven的语法,Gradle为什么找不到提供的方法 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' lin

如果这是Maven的语法,Gradle为什么找不到提供的方法

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 [{group=javax, name=javaee-api, version=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: 8.684 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 group: 'javax', name: 'javaee-api', version: '7.0'
}
关于:


以便使用maven中提供的
范围的依赖项构建。您可能希望将
build.gradle
配置为以下内容:

configurations {
    provided
}

sourceSets {
    main.compileClasspath += configurations.provided
    test.compileClasspath += configurations.provided
    test.runtimeClasspath += configurations.provided
}
然后进一步利用您的依赖关系,如:

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

或者,您可以按照以下方式进行操作:

dependencies {
    ...
    compileOnly 'javax:javaee-api:7.0'
}

正如maven中央存储库中提到的,
compileOnly
选项起作用;下载javaee-api-7.0.pom并与之关联,然后构建
EAR
——看起来不错。为什么maven页面给出不同的说明?阅读您的精美手册链接,谢谢。@Thufir我宁愿相信这一点