I am trying to list JIRA projects with the Java SDK following https://www.baeldung.com/jira-rest-api (I could not find another example in Google for this) with the following code:
public static void main(String[] args) {
JiraRestClient jiraRestClient = getJiraRestClient(URI.create("uri"),"username","token");
try {
Iterable<BasicProject> projects = jiraRestClient.getProjectClient().getAllProjects().get();
projects.forEach(basicProject -> System.out.println(basicProject.getName()));
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (ExecutionException e) {
throw new RuntimeException(e);
}
}
private static JiraRestClient getJiraRestClient(URI uri, String username, String password) {
return new AsynchronousJiraRestClientFactory()
.createWithBasicHttpAuthentication(uri, username, password);
}
However, it returns this error:
Exception in thread "main" java.lang.NoClassDefFoundError: io/atlassian/fugue/Suppliers
at com.atlassian.httpclient.apache.httpcomponents.ApacheAsyncHttpClient.<clinit>(ApacheAsyncHttpClient.java:80)
at com.atlassian.httpclient.apache.httpcomponents.DefaultHttpClientFactory.doCreate(DefaultHttpClientFactory.java:61)
at com.atlassian.httpclient.apache.httpcomponents.DefaultHttpClientFactory.create(DefaultHttpClientFactory.java:36)
at com.atlassian.jira.rest.client.internal.async.AsynchronousHttpClientFactory.createClient(AsynchronousHttpClientFactory.java:68)
at com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory.create(AsynchronousJiraRestClientFactory.java:36)
at com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory.createWithBasicHttpAuthentication(AsynchronousJiraRestClientFactory.java:42)
at JiraPlayground.getJiraRestClient(JiraPlayground.java:30)
at JiraPlayground.main(JiraPlayground.java:13)
Caused by: java.lang.ClassNotFoundException: io.atlassian.fugue.Suppliers
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 8 more
Here are my dependencies:
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-java-client-core</artifactId>
<version>5.2.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.atlassian.fugue/fugue -->
<dependency>
<groupId>io.atlassian.fugue</groupId>
<artifactId>fugue</artifactId>
<version>5.0.0</version>
<scope>provided</scope>
</dependency>
Any idea how to run the code correctly?
This is working for me:
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>untitled1</artifactId>
<version>1.0-SNAPSHOT</version>
<repositories>
<repository>
<id>Atlassian</id>
<url>https://packages.atlassian.com/mvn/maven-atlassian-external/</url>
</repository>
</repositories>
<properties>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-java-client-core</artifactId>
<version>5.2.4</version>
</dependency>
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-java-client-api</artifactId>
<version>5.2.4</version>
</dependency>
<dependency>
<groupId>io.atlassian.fugue</groupId>
<artifactId>fugue</artifactId>
<version>5.0.0</version>
</dependency>
</dependencies>
</project>
As mentioned in https://stackoverflow.com/a/75527051/309683, make sure fuge
is not marked as provided
if you are running the app outside Jira (e.g. not a plugin/extension).
Then this code should work:
package org.example;
import com.atlassian.jira.rest.client.api.JiraRestClient;
import com.atlassian.jira.rest.client.api.JiraRestClientFactory;
import com.atlassian.jira.rest.client.api.domain.BasicProject;
import com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory;
import java.net.URI;
public class Main {
private static final String JIRA_URL = "https://your-jira-url.com";
private static final String JIRA_USERNAME = "your-jira-username";
private static final String JIRA_PASSWORD = "your-jira-password";
public static void main(String[] args) throws Exception {
URI jiraServerUri = new URI(JIRA_URL);
JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
try (JiraRestClient client = factory.createWithBasicHttpAuthentication(jiraServerUri, JIRA_USERNAME, JIRA_PASSWORD)) {
Iterable<BasicProject> projects = client.getProjectClient().getAllProjects().claim();
for (BasicProject project : projects) {
System.out.println(project.getKey() + ": " + project.getName());
}
}
}
}