Jersey / JAX-RS项目中的Gradle'无法解析所有依赖项以进行配置'

jsh*_*303 4 java rest jersey gradle maven

我想将JSON依赖项放在build.gradle中,以修复错误MessageBodyWriter not found for media type=application/json。在上一个问题中,我了解到很有可能在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
}
Run Code Online (Sandbox Code Playgroud)

现在我得到的错误 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
Run Code Online (Sandbox Code Playgroud)

我正在检查是否包含gradle和Jersey 的正确版本(在web.xml中,我看到2.5,但2.5仍然给出相同的错误)。在我的jersey服务器端代码中,唯一与jersey相关的软件包是import org.glassfish.jersey.server.mvc.Viewable;

有人给我一个提示,我需要补充什么?

Ati*_*gur 5

在build.gradle中定义存储库,如下所示。

repositories {
      maven  {
          url "http://repo1.maven.org/maven2"
      }
}
Run Code Online (Sandbox Code Playgroud)

或以下

repositories {
    mavenCentral()
}
Run Code Online (Sandbox Code Playgroud)

Gradle帮助第8章。依赖管理基础知识8.5。存储库给出了其他示例。

您还应该根据现有版本更改依赖性。我链接了版本页面,因为您请求的版本“ 2.3.10”在maven存储库中不存在。

dependencies {
    compile 'org.glassfish.jersey.media:jersey-media-json-jackson:2.5'
}
Run Code Online (Sandbox Code Playgroud)