java - AsynchronousJiraRestClientFactory 无法转换为 JiraRestClientFactory

标签 java rest maven jira pom.xml

我正在尝试使用 REST API 进行一些非常基本的 Jira 交互,但每一个障碍都失败了。我什至还没有尝试发送任何请求或任何东西,我只是在尝试初始化客户端。我从其他使用它的人那里在线获得了以下大部分代码,但由于某种原因,我无法让它工作。

我一直收到这个编译错误:

com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory cannot be converted to com.atlassian.jira.rest.client.JiraRestClientFactory

我的 .java 文件如下所示:

package com.atlassian.tutorial.macro;

import com.atlassian.confluence.content.render.xhtml.ConversionContext;
import com.atlassian.confluence.macro.Macro;
import com.atlassian.confluence.macro.MacroExecutionException;

import com.atlassian.jira.rest.client.JiraRestClient;
import com.atlassian.jira.rest.client.JiraRestClientFactory;
import com.atlassian.jira.rest.client.domain.User;
import com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory;
import com.atlassian.util.concurrent.Promise;

import java.net.URI;

import java.util.Map;

public class helloworld implements Macro {

    private static final String JIRA_URL = "http://localhost:2990/jira";
    private static final String JIRA_ADMIN_USERNAME = "admin";
    private static final String JIRA_ADMIN_PASSWORD = "admin";

    public String execute(Map<String, String> map, String s, ConversionContext conversionContext) throws MacroExecutionException {

        JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
        URI uri = new URI(JIRA_URL);
        JiraRestClient client = factory.createWithBasicHttpAuthentication(uri, JIRA_ADMIN_USERNAME, JIRA_ADMIN_PASSWORD);
   }

        public BodyType getBodyType() { return BodyType.NONE; }
        public OutputType getOutputType() { return OutputType.BLOCK; }
}

我的 pom.xml 文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>com.atlassian.tutorial</groupId>
<artifactId>myConfluenceMacro</artifactId>
<version>1.0.0-SNAPSHOT</version>

<organization>
    <name>Test</name>
    <url>http://www.example.com/</url>
</organization>

<name>myConfluenceMacro</name>
<description>This is the com.atlassian.tutorial:myConfluenceMacro plugin for Atlassian Confluence.</description>
<packaging>atlassian-plugin</packaging>

<dependencies>
     <!-->JIRA LINK STUFF<-->
    <dependency>
        <groupId>com.atlassian.jira</groupId>
        <artifactId>jira-rest-java-client-core</artifactId>
        <version>5.1.2-2bd0a62e</version>
    </dependency>

    <dependency>
        <groupId>com.atlassian.jira</groupId>
        <artifactId>jira-rest-java-client-parent</artifactId>
        <version>4.0.0</version>
        <type>pom</type>
    </dependency>

     <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-client</artifactId>
        <version>1.9</version>
    </dependency>

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

    <dependency>
        <groupId>com.atlassian.jira</groupId>
        <artifactId>jira-api</artifactId>
        <version>8.2.1</version>
        <scope>provided</scope>
        <exclusions>
            <!-- JRJC depends on a newer version of atlassian-util-concurrent than the one provided by JIRA -->
            <exclusion>
                <groupId>com.atlassian.util.concurrent</groupId>
                <artifactId>atlassian-util-concurrent</artifactId>
            </exclusion>
            <!-- JRJC uses 4.0 of the apache httpclient. JIRA bundled version 3.x -->
            <exclusion>
                <groupId>commons-httpclient</groupId>
                <artifactId>commons-httpclient</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

    <dependency>
        <groupId>com.atlassian.jira</groupId>
        <artifactId>jira-rest-java-client</artifactId>
        <version>2.0.0-m2</version>
        <!--
         JIRA will already provide a number of dependencies that JRJC needs. We need to exclude them from the
         JRJC dependency as we don't want to package them up inside the plugin.
        -->
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
            <exclusion>
                <groupId>joda-time</groupId>
                <artifactId>joda-time</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.sun.jersey</groupId>
                <artifactId>jersey-json</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.google.guava</groupId>
                <artifactId>guava</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.atlassian.sal</groupId>
                <artifactId>sal-api</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.atlassian.event</groupId>
                <artifactId>atlassian-event</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
            </exclusion>
            <exclusion>
                <groupId>commons-lang</groupId>
                <artifactId>commons-lang</artifactId>
            </exclusion>
            <exclusion>
                <groupId>commons-codec</groupId>
                <artifactId>commons-codec</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.sun.jersey</groupId>
                <artifactId>jersey-core</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <!-->/////////////////////////<-->


    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.10</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.atlassian.confluence</groupId>
        <artifactId>confluence</artifactId>
        <version>${confluence.version}</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>com.atlassian.plugin</groupId>
        <artifactId>atlassian-spring-scanner-annotation</artifactId>
        <version>${atlassian.spring.scanner.version}</version>
        <scope>compile</scope>
    </dependency>

    <dependency>
        <groupId>com.atlassian.plugin</groupId>
        <artifactId>atlassian-spring-scanner-runtime</artifactId>
        <version>${atlassian.spring.scanner.version}</version>
        <scope>runtime</scope>
    </dependency>

    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <version>1</version>
        <scope>provided</scope>
    </dependency>

    <!-- WIRED TEST RUNNER DEPENDENCIES -->
    <dependency>
        <groupId>com.atlassian.plugins</groupId>
        <artifactId>atlassian-plugins-osgi-testrunner</artifactId>
        <version>${plugin.testrunner.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax.ws.rs</groupId>
        <artifactId>jsr311-api</artifactId>
        <version>1.1.1</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.2.2-atlassian-1</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>com.atlassian.maven.plugins</groupId>
            <artifactId>confluence-maven-plugin</artifactId>
            <version>${amps.version}</version>
            <extensions>true</extensions>
            <configuration>
                <productVersion>${confluence.version}</productVersion>
                <productDataVersion>${confluence.data.version}</productDataVersion>
                <enableQuickReload>true</enableQuickReload>

                <!-- See here for an explanation of default instructions: -->
                <!-- https://developer.atlassian.com/docs/advanced-topics/configuration-of-instructions-in-atlassian-plugins -->
                <instructions>
                    <Atlassian-Plugin-Key>${atlassian.plugin.key}</Atlassian-Plugin-Key>

                    <!-- Add package to export here -->
                    <Export-Package>
                        com.atlassian.tutorial.api,
                    </Export-Package>

                    <!-- Add package import here -->
                    <Import-Package>
                        org.springframework.osgi.*;resolution:="optional",
                        org.eclipse.gemini.blueprint.*;resolution:="optional",
                        *
                    </Import-Package>

                    <!-- Ensure plugin is spring powered -->
                    <Spring-Context>*</Spring-Context>
                </instructions>
            </configuration>
        </plugin>

        <plugin>
            <groupId>com.atlassian.plugin</groupId>
            <artifactId>atlassian-spring-scanner-maven-plugin</artifactId>
            <version>${atlassian.spring.scanner.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>atlassian-spring-scanner</goal>
                    </goals>
                    <phase>process-classes</phase>
                </execution>
            </executions>
            <configuration>
                <scannedDependencies>
                    <dependency>
                        <groupId>com.atlassian.plugin</groupId>
                        <artifactId>atlassian-spring-scanner-external-jar</artifactId>
                    </dependency>
                </scannedDependencies>
                <verbose>false</verbose>
            </configuration>
        </plugin>
    </plugins>
</build>

<properties>
    <confluence.version>6.14.0</confluence.version>
    <confluence.data.version>6.14.0</confluence.data.version>
    <amps.version>8.0.2</amps.version>
    <plugin.testrunner.version>2.0.1</plugin.testrunner.version>
    <atlassian.spring.scanner.version>1.2.13</atlassian.spring.scanner.version>
    <!-- This property ensures consistency between the key in atlassian-plugin.xml and the OSGi bundle's key. -->
    <atlassian.plugin.key>${project.groupId}.${project.artifactId}</atlassian.plugin.key>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

最佳答案

在您的 Maven POM 中,您使用了两个不同版本的 jira 实现。 它们很可能具有相同的命名方案,并且可能是您收到“AsynchronousJiraRestClientFactory 无法转换为 JiraRestClientFactory”错误的原因,因为即使命名相同,这些类也来自两个不同的依赖项 jar (5.1.2) & (4.0.0)

<dependency>
        <groupId>com.atlassian.jira</groupId>
        <artifactId>jira-rest-java-client-core</artifactId>
        <version>5.1.2-2bd0a62e</version>
    </dependency>

    <dependency>
        <groupId>com.atlassian.jira</groupId>
        <artifactId>jira-rest-java-client-parent</artifactId>
        <version>4.0.0</version>
        <type>pom</type>
    </dependency>

关于java - AsynchronousJiraRestClientFactory 无法转换为 JiraRestClientFactory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56904773/

相关文章:

java - 最大化(排序)Neo4j 数据库中的版本号元素

java - 在 Mac 和 PC 上运行的 .NET 和 Java 之间进行选择

java - 如何使用多对多字段原生查询 WHERE IN?

http - RESTful 集合和控制成员详细信息

maven - 'parent.relativePath' 指向我的 com.mycompany :MyProject instead of org. apache :apache - Why?

java - 无法使用 spring WebClient : always 400 POST 请求

java - 构建新应用程序 : Java jax-rs ee6 restful web service with a html5 front-end using backbone. js

java - 是否有像 FRAPI (PHP) 这样但适用于 Java 的 REST Web 服务 API 提供程序?

java - 在集成测试之前启动主应用程序和测试应用程序

java - 标记为运行太长的 JUnit 测试失败