【问题标题】:Cannot create AsynchronousJiraRestClientFactory (Dependency Issue)无法创建 AsynchronousJiraRestClientFactory(依赖问题)
【发布时间】:2015-11-07 00:55:32
【问题描述】:

我之前用 Java 制作了一个 restful 客户端应用程序来大规模处理票证并加快工作流程,但是,我想创建一个更全面的应用程序,它利用实际的 JIRA api 而不是在我自己的解决方案中解析 JSON。 我有一个非常简单的代码块来创建客户端:

public class SimpleMain {
  public static void main(String[] args) {
    try {
      JiraRestClient client = new AsynchronousJiraRestClientFactory()
        .createWithBasicHttpAuthentication(new URI("https://jira.redacted.com"), "redacted", "redacted");
    } catch (URISyntaxException e) {
      e.printStackTrace();
    }
  }
}

尝试创建简单的 AsynchronousJiraRestClientFactory 会导致以下异常:

15:12:06.625 [main] DEBUG c.a.j.r.c.i.a.AsynchronousHttpClientFactory$MavenUtils - Could not find version for maven artifact com.atlassian.jira:jira-rest-java-com.atlassian.jira.rest.client
15:12:06.633 [main] DEBUG c.a.j.r.c.i.a.AsynchronousHttpClientFactory$MavenUtils - Got the following exception
java.lang.NullPointerException: null
at java.util.Properties$LineReader.readLine(Properties.java:434) ~[na:1.8.0_51]
at java.util.Properties.load0(Properties.java:353) ~[na:1.8.0_51]
at java.util.Properties.load(Properties.java:341) ~[na:1.8.0_51]
at com.atlassian.jira.rest.client.internal.async.AsynchronousHttpClientFactory$MavenUtils.getVersion(AsynchronousHttpClientFactory.java:158) ~[jira-rest-java-client-core-3.0.0.jar:na]
at com.atlassian.jira.rest.client.internal.async.AsynchronousHttpClientFactory$RestClientApplicationProperties.getVersion(AsynchronousHttpClientFactory.java:121) [jira-rest-java-client-core-3.0.0.jar:na]
at com.atlassian.httpclient.apache.httpcomponents.DefaultHttpClient.getUserAgent(DefaultHttpClient.java:168) [atlassian-httpclient-apache-httpcomponents-0.13.2.jar:na]
at com.atlassian.httpclient.apache.httpcomponents.DefaultHttpClient.<init>(DefaultHttpClient.java:139) [atlassian-httpclient-apache-httpcomponents-0.13.2.jar:na]
at com.atlassian.jira.rest.client.internal.async.AsynchronousHttpClientFactory.createClient(AsynchronousHttpClientFactory.java:53) [jira-rest-java-client-core-3.0.0.jar:na]
at com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory.create(AsynchronousJiraRestClientFactory.java:35) [jira-rest-java-client-core-3.0.0.jar:na]
at com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory.createWithBasicHttpAuthentication(AsynchronousJiraRestClientFactory.java:42) [jira-rest-java-client-core-3.0.0.jar:na]
at jiratest.SimpleMain.main(SimpleMain.java:13) [classes/:na]
Exception in thread "main" java.lang.NoSuchMethodError: org.apache.http.nio.client.HttpAsyncClient.start()V
at com.atlassian.httpclient.apache.httpcomponents.DefaultHttpClient.<init>(DefaultHttpClient.java:162)
Disconnected from the target VM, address: '127.0.0.1:53429', transport: 'socket'
at com.atlassian.jira.rest.client.internal.async.AsynchronousHttpClientFactory.createClient(AsynchronousHttpClientFactory.java:53)
at com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory.create(AsynchronousJiraRestClientFactory.java:35)
at com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory.createWithBasicHttpAuthentication(AsynchronousJiraRestClientFactory.java:42)
at jiratest.SimpleMain.main(SimpleMain.java:13)

从我一直在阅读的内容来看,这是一个依赖问题,因为库不同。这是我正在使用的:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>1.8</java.version>
    <pojomatic.version>2.0.1</pojomatic.version>
    <jira-api.version>6.1.1</jira-api.version>
    <jira-rest-java-client-core.version>3.0.0</jira-rest-java-client-core.version>
    <httpcore.version>4.4.1</httpcore.version>
    <commons-io.version>2.4</commons-io.version>
</properties>

<dependencies>
    <dependency>
        <groupId>com.atlassian.jira</groupId>
        <artifactId>jira-api</artifactId>
        <version>${jira-api.version}</version>
    </dependency>
    <dependency>
        <groupId>com.atlassian.jira</groupId>
        <artifactId>jira-rest-java-client-core</artifactId>
        <version>${jira-rest-java-client-core.version}</version>
    </dependency>

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>${httpcore.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore</artifactId>
        <version>${httpcore.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpcore-nio</artifactId>
        <version>${httpcore.version}</version>
    </dependency>

    <dependency>
        <groupId>org.pojomatic</groupId>
        <artifactId>pojomatic</artifactId>
        <version>${pojomatic.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-batch</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

有人知道我应该使用什么版本吗?我仍然缺少依赖项吗?我一直在阅读 atlasian q/a 和各种谷歌文档,我想我已经很接近了,但我不确定我还缺少什么。

提前感谢大家:)

【问题讨论】:

    标签: java maven jira jira-rest-api


    【解决方案1】:

    在互联网上尝试了所有其他解决方案后,修改我的 log4j2 配置对我有用:

    <?xml version="1.0" encoding="UTF-8"?>
    <Configuration status="DEBUG">
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%msg%n" />
        </Console>
        <File name="File" fileName="qed.log" immediateFlush="true" append="true">
            <PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
        </File>
    </Appenders>
    <Loggers>
        <Logger name="com.atlassian.jira.rest.client.internal.async.AsynchronousHttpClientFactory$MavenUtils" level="OFF"/>
        <Root level="DEBUG">
            <AppenderRef ref="Console" />
            <AppenderRef ref="File"/>
        </Root>
    </Loggers>
    

    配置的关键部分是:

    <Logger name="com.atlassian.jira.rest.client.internal.async.AsynchronousHttpClientFactory$MavenUtils" level="OFF"/>
    

    显然它不能解决问题,但它确实隐藏了它。

    尽管 NullPointerException 看起来很讨厌,但它对 ApacheAsyncHttpClient 的创建没有影响,请参阅:

            try {
                resourceAsStream = MavenUtils.class.getResourceAsStream(String
                        .format("/META-INF/maven/%s/%s/pom.properties", groupId, artifactId));
                props.load(resourceAsStream);
                return props.getProperty("version", UNKNOWN_VERSION);
            } catch (Exception e) {
                logger.debug("Could not find version for maven artifact {}:{}", groupId, artifactId);
                logger.debug("Got the following exception", e);
                return UNKNOWN_VERSION;
            } finally {
    

    【讨论】:

    • 你必须回头看看我的堆栈跟踪:at jiratest.SimpleMain.main(SimpleMain.java:13),这实际上阻止了我的应用程序运行。所以,不幸的是,这和你看到的不一样。
    【解决方案2】:

    我遇到了同样的问题,并通过以下方式解决了它: 我两个都有

    <dependency>
      <groupId>com.atlassian.jira</groupId>
      <artifactId>jira-rest-java-client-core</artifactId>
      <version>2.0.0-m25</version>
    </dependency>
    

    <dependency>
      <groupId>com.atlassian.httpclient</groupId>
      <artifactId>atlassian-httpclient-apache-httpcomponents</artifactId>
      <version>0.13.2</version>
    </dependency>
    

    在我的 pom.xml 文件中。原来client-core里面已经有httpcomponents了,他们发生了冲突。删除第二个依赖项解决了问题

    【讨论】:

      【解决方案3】:

      实际问题在于 Spring 的传递依赖覆盖了 atlassian 的传递依赖。解决此问题的方法是将依赖关系重新调整为 jrjc 需要的版本,而不是更新的版本。

      <dependencyManagement>
        <dependencies>
          <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.2.1-atlassian-2</version>
          </dependency>
          <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpasyncclient</artifactId>
            <version>4.0-beta3-atlassian-1</version>
          </dependency>
        </dependencies>
      </dependencyManagement>
      

      注意:这些版本可能会在未来的版本中发生变化,但它们适用于 JRJC 核心版本 3.0.0。你可以通过阅读mvn dependency:tree 的输出来发现,它会说:httpasyncclient:jar:4.0.2:compile - version managed from 4.0-beta3-atlassian-1 这让你知道maven 正在使用httpsyncclient 的4.0.2 版本,所以你需要将它覆盖回4.0-beta3-atlassian-1 .

      【讨论】:

      • dependency:tree 中,我看到这两个依赖项完全正确,并且添加您建议的dependecyManagement 部分无助于摆脱NullPointerException :(
      • 您可能有另一个与 jrjc 核心冲突的依赖项。运行mvn dependency:tree 并查看您是否在其他任何人身上看到任何version managed from 消息。将它们拉到dependencyManagement 部分中的from 版本,然后冲洗并重复。有时,如果你有多个依赖项,你实际上会被拉起 MULTIPLE 多次而不是只为给定的依赖项拉一次,所以唯一知道的方法是管理/检查多次。
      • @dokaspar 这很可能为时已晚,我刚刚意识到这可能是因为您需要清理旧依赖项的 maven 项目。 mvn clean install -B -U 删除并收集 pom 文件定义的最新依赖项。
      猜你喜欢
      • 2021-05-04
      • 2017-04-10
      • 2011-12-08
      • 1970-01-01
      • 2019-11-16
      • 1970-01-01
      • 1970-01-01
      • 2014-03-07
      • 1970-01-01
      相关资源
      最近更新 更多