Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot create AsynchronousJiraRestClientFactory (Dependency Issue)

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

like image 290
Paul Nelson Baker Avatar asked Aug 13 '15 21:08

Paul Nelson Baker


2 Answers

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.

like image 140
Paul Nelson Baker Avatar answered Oct 23 '22 21:10

Paul Nelson Baker


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

like image 1
Maksim Mukhammedov Avatar answered Oct 23 '22 21:10

Maksim Mukhammedov