Cannot create AsynchronousJiraRestClientFactory (Dependency Issue)

╄→гoц情女王★ 提交于 2019-12-10 14:01:59

问题


I previously made a restful client application in Java to mass-manipulate tickets and expedite workflow, however, I want to create a more holistic application that utilizes the actual JIRA api instead of parsing JSON in my own solution. I have a very simple code-block to create a client:

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();
    }
  }
}

Attempting to create a simple AsynchronousJiraRestClientFactory results in the following exception:

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)

From what I have been reading, this is a dependency issue because of differing libraries. Here is what I'm using:

<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>

Does anyone know what versions I should be using? Am I still missing dependencies? I've been reading through atlasian q/a's and various google documents and I think I'm close but I'm not sure what I'm still missing.

Thanks to all in advance :)


回答1:


The actual issue lays in the fact that Spring's transitive dependencies override atlassian's transitive dependencies. The way to fix this is to wrangle the dependencies back to what the jrjc needs them to be, instead of the more up to date versions.

<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>

NOTE: These versions will probably change in future releases, but they work for JRJC core version 3.0.0. You can find out by reading the output of mvn dependency:tree, it will say something like: httpasyncclient:jar:4.0.2:compile - version managed from 4.0-beta3-atlassian-1 which lets you know that maven is using version 4.0.2 of httpsyncclient, so you need to override it back to 4.0-beta3-atlassian-1.




回答2:


I've got the same issue, and solved it the following way: I had both

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

and

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

in my pom.xml file. Turned out client-core already had httpcomponents inside, and they clashed. Removing second dependency fixed the issue




回答3:


After trying all the other solutions on the internet, modifying my log4j2 configuration worked for me:

<?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>

The key part of the configuration is:

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

Obviously it doesn't fix the problem, but it does hide it.

As nasty as the NullPointerException seems to be, it has no effect on the creation of the ApacheAsyncHttpClient, see:

        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 {


来源:https://stackoverflow.com/questions/31998691/cannot-create-asynchronousjirarestclientfactory-dependency-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!