我想将jSON依赖项放在build.gradle中,以便修复错误MessageBodyWriter not found for media type=application/json
。
在我的previous question中,我了解到很可能我的build.gradle文件中没有包含JSON作为依赖项。
我添加了依赖项,如下所示(第8行,最后compile
)
apply plugin: 'war'
apply plugin: 'jetty'
dependencies {
compile fileTree(dir: 'lib', include: '**/*.jar')
compile(project(":qa-common"))
compile(project(":alm"))
compile 'org.glassfish.jersey.media:jersey-media-json-jackson:2.3.10'
}
jettyRun {
httpPort = 8080
reload = 'automatic'
scanIntervalSeconds = 2
daemon = false
}
现在我收到错误Could not resolve all dependencies for configuration'
FAILURE: Build failed with an exception.
* What went wrong:
Could not resolve all dependencies for configuration ':qa-automation-console:compile'.
> Cannot resolve external dependency org.glassfish.jersey.media:jersey-media-json-jackson:2.3.10 because no repositories are defined.
Required by:
qaauto:qa-automation-console:unspecified
* 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: 5.273 secs
我正在检查我是否包含了correct version of gradle和Jersey(在web.xml中我看到2.5但是2.5仍然给出了相同的错误)。在我的球衣服务器侧码中,与球衣相关的唯一包是import org.glassfish.jersey.server.mvc.Viewable;
任何人都能告诉我需要添加的内容吗?
答案 0 :(得分:4)
在build.gradle中定义存储库,如下所示。
repositories {
maven {
url "http://repo1.maven.org/maven2"
}
}
或关注
repositories {
mavenCentral()
}
Gradle Help Chapter 8. Dependency Management Basics 8.5. Repositories给出了其他例子。
您还应该根据现有versions更改您的依赖关系。我联系了版本页面,因为您要求"版本2.3.10"在maven存储库中不存在。
dependencies {
compile 'org.glassfish.jersey.media:jersey-media-json-jackson:2.5'
}