Gradle:找不到提供的方法()(group) [英] Gradle: Could not find method provided() (group)
本文介绍了Gradle:找不到提供的方法()(group)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么当这是提供的方法 /7.0rel =nofollow noreferrer>指定 Maven?
thufir @ doge:〜/ NetBeansProjects / gradleEAR
thufir @ doge:〜/ NetBeansProjects / gradleEAR $ gradle clean
失败:构建失败,出现异常。
*其中:
构建文件'/home/thufir/NetBeansProjects/gradleEAR/build.gradle'行:40
*出错:
评估根项目gradleEAR时发生问题。
>对于类型为org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler的对象,找不到参数[{group = javax,name = javaee-api,version = 7.0}]的方法provide()。
*尝试:
使用--stacktrace选项运行以获取堆栈跟踪。使用--info或--debug选项运行以获取更多日志输出。
构建失败
总时间:8.684秒
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-服务'
licenseAgree ='是'
}
储存库{
jcenter()
}
jar {
manifest {
属性'Main-Class':'net.bounceme.doge.json.Main'
}
}
任务fatJar(type :Jar){
baseName = project.name +'-all'
from {configurations.compile.collect {it.isDirectory()?它:zipTree(it)}}
with jar
manifest {
attributes'Implementation-Title':'Gradle Quickstart','Implementation-Version':'3.4.0'
属性'Main-Class':'net.bounceme.doge.json.Main'
}
}
依赖关系{
编译组:'javax.json ',名称:'javax.json-api',版本:'1.1'
编译组:'org.glassfish',名称:'javax.json',版本:'1.1'
提供的组: 'javax',name:'javaee-api',version:'7.0'
}
参考:
Gradle如何解决javaee-api依赖关系以构建EAR?
解决方案 div>
为了在maven中使用 build.gradle
配置为以下内容:
配置{
提供
}
sourceSets {
main.compileClasspath + =配置。提供
test.compileClasspath + =配置。提供
test.runtimeClasspath + = configurations.provided
}
然后进一步利用你的依赖关系as:
依赖关系{
编译组:'javax.json',名称:'javax.json-api' ,版本:'1.1'
编译组:'org.glassfish',名称:'javax.json',版本:'1.1'
提供组:'javax',名称:'javaee-api' ,版本:'7.0'
}
或者您可以按照 compileOnly
方式o如下所示:
依赖关系{
...
compileOnly'javax:javaee-api: 7.0'
}
在maven中央仓库中也提到这里
Why can't Gradle find the method provided
when this is the syntax specified by 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'
}
In reference to:
How does Gradle resolve the javaee-api dependency to build an EAR?
解决方案
In order to use dependencies build with provided
scope in maven. You might want to configure your build.gradle
to the following:
configurations {
provided
}
sourceSets {
main.compileClasspath += configurations.provided
test.compileClasspath += configurations.provided
test.runtimeClasspath += configurations.provided
}
and then further make use of your dependencies as:
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'
}
Or you can follow compileOnly
way of doing it as:
dependencies {
...
compileOnly 'javax:javaee-api:7.0'
}
As also mentioned in the maven central repository here
这篇关于Gradle:找不到提供的方法()(group)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文