我之前在Java中创建了一个非常好的客户端应用程序来批量操作票证并加快工作流程,但是,我想创建一个更全面的应用程序,它利用实际的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>
有谁知道我应该使用哪些版本?我还缺少依赖吗?我一直在阅读地图集q / a和各种谷歌文档,我想我已经接近了,但我不确定我还缺少什么。
提前感谢所有人:)
答案 0 :(得分: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正在使用httpsyncclient
版本4.0.2,所以你需要覆盖它回到4.0-beta3-atlassian-1
。
答案 1 :(得分:1)
我遇到了同样的问题,并通过以下方式解决了这个问题: 我有两个
<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文件中。原来客户核心里面已经有了httpcomponents,他们发生了冲突。删除第二个依赖项修复了问题
答案 2 :(得分: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 {