2015-08-13 72 views
3

我以前在Java中創建了一個穩定的客戶端應用程序來批量操縱票據並加速工作流,但是,我想創建一個更全面的應用程序,它利用實際的JIRA API而不是解析JSON自己解決。 我有一個非常簡單的代碼塊創建一個客戶端:無法創建AsynchronousJiraRestClientFactory(依賴項問題)

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> 

有誰知道我應該使用什麼版本?我仍然缺少依賴關係嗎?我一直在閱讀亞特蘭大的q/a和各種谷歌文檔,我認爲我很接近,但我不確定我還缺少什麼。

感謝所有提前:)

回答

4

實際問題的事實是奠定了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正在使用版本4.0.2的httpsyncclient,所以你需要覆蓋它回到4.0-beta3-atlassian-1

+0

在'依賴性:tree'我看到exaclty這兩個依賴和增加你的建議的dependecyManagement部分沒有幫助擺脫NullPointerException :( – dokaspar

+0

可能你有另一個與jrjc核心發生衝突的依賴項。運行'mvn dependency:tree'並查看你是否看到任何'受管理的'消息在dependencyManagement部分將它們拉到from版本,然後漂洗並重復。有時候,如果你有多個依賴關係,你實際上會被拉到多個ti mes,而不是一次給定的依賴關係,所以唯一的方法是知道多次管理/檢查。 –

+0

@dokaspar這很可能已經太晚了,我只是意識到這可能是因爲你需要清理你的老依賴的maven項目。 'mvn clean install -B -U'去除然後收集由pom文件定義的最新的依賴關係。 –

0

我已經得到了同樣的問題,並解決它通過以下方式: 我在pom.xml文件中有兩個

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

。原來客戶端內核已經有了httpcomponents,並且發生了衝突。卸下第二依賴固定的問題

0

試圖在互聯網上的所有其他解決方案後,修改我的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 { 
+0

你必須回頭看我的stacktrace:'在jiratest.SimpleMain.main(SimpleMain.java:13)',這實際上阻止了我的應用程序運行。所以,不幸的是,這與你所看到的不一樣。 –