gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 09:47:22 24 4
gpt4 key购买 nike

为什么Gradle找不到方法provided当这是语法时 specified通过 Maven?

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

在参照:

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

最佳答案

为了使用依赖项构建 provided 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'
}

或者您可以关注 compileOnly 这样做的方式:
dependencies {
...
compileOnly 'javax:javaee-api:7.0'
}

正如在 maven 中央存储库 here 中提到的一样

关于maven - Gradle:找不到提供的方法()(组),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45808956/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com