【问题标题】:Gradle 'Could not resolve all dependencies for configuration' in Jersey/JAX-RS project泽西/JAX-RS 项目中的 Gradle '无法解析配置的所有依赖项'
【发布时间】:2015-10-28 19:39:23
【问题描述】:

我想将 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;

有人告诉我我需要添加什么吗?

【问题讨论】:

    标签: java rest maven gradle jersey


    【解决方案1】:

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

    repositories {
          maven  {
              url "http://repo1.maven.org/maven2"
          }
    }
    

    或关注

    repositories {
        mavenCentral()
    }
    

    Gradle Help Chapter 8. Dependency Management Basics 8.5. Repositories 给出了其他例子。

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

    dependencies {
        compile 'org.glassfish.jersey.media:jersey-media-json-jackson:2.5'
    }
    

    【讨论】:

    • 谢谢你,这很有帮助。在哪里/如何找到与我的 Maven 存储库匹配的确切 URL?为了匹配“版本”,我需要在本地文件中找到任何内容吗? (像上面例子中提到的maven2?)
    • 如果你使用标准的 maven 中心 url,你不需要找到确切的 url。我添加了另一个使用 mavenCentral() 用法的示例
    • 我尝试了两个存储库,但又出现了另一个错误Could not resolve org.glassfish.jersey.media:jersey-media-json-jackson:2.5. > Could not get resource https://repo1.maven.org/maven2/org/glassfish/jersey/media/jersey-media-json-jackson/2.5/jersey-media-json-jackson-2.5.pom.> Could not GET https://repo1.maven.org/maven2/org/glassfish/jersey/media/jersey-media-json-jackson/2.5/jersey-media-json-jackson-2.5.pom.> Connection to https://repo1.maven.org refused
    • @JiajuShen 你用的是什么版本的 Jersey?您可能只想下载所有 jar,因为这似乎是您管理 jar 的方式。如果连接被拒绝,听起来可能是防火墙问题。
    • @JiajuShen 我的意思是我链接到的答案提供了一堆罐子的下载链接。使用 Maven 或 Gradle,当我们声明像 jersey-media-json-jackson 这样的依赖项时,该工具将下载该 jar 以及它所依赖的所有 jar。在jersey-media-json-jackson 的情况下,来自该链接的所有 jar 都将被拉入。但由于下载无法在您的 Gradle 上运行(可能被防火墙拒绝),您需要单独下载所有这些 jar,并且无论您放在哪里所有其他应用程序罐子,把这些罐子放在那里。我不知道还能怎么解释。
    猜你喜欢
    • 2016-10-09
    • 1970-01-01
    • 1970-01-01
    • 2016-02-14
    • 2014-11-17
    • 2016-10-31
    • 2017-03-17
    • 2018-02-11
    • 2020-12-20
    相关资源
    最近更新 更多