I’m currently working on a Gradle script that creates versions in JIRA using REST API calls. However, I discovered the Atlassian JIRA REST Java client library and want to switch to using this instead of direct API calls.
I’m running into issues when trying to implement this library in my Java project. Here’s what I’m trying to accomplish:
import com.atlassian.jira.rest.client.api.JiraRestClient;
import com.atlassian.jira.rest.client.api.domain.*;
import com.atlassian.jira.rest.client.api.domain.input.IssueInputBuilder;
import com.atlassian.jira.rest.client.api.domain.input.WorkflowTransitionInput;
import com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory;
import java.net.URI;
import java.util.concurrent.ExecutionException;
public class JiraClientDemo {
private static final String JIRA_URL = "http://localhost:8080/jira";
private static final String USERNAME = "testuser";
private static final String PASSWORD = "testpass";
public static void main(String[] args) throws ExecutionException, InterruptedException {
AsynchronousJiraRestClientFactory clientFactory = new AsynchronousJiraRestClientFactory();
JiraRestClient jiraClient = clientFactory.createWithBasicHttpAuthentication(
URI.create(JIRA_URL), USERNAME, PASSWORD);
try {
// Get server information
ServerInfo serverData = jiraClient.getMetadataClient().getServerInfo().get();
System.out.println("Connected to: " + serverData.getServerTitle());
// Fetch all available projects
Iterable<BasicProject> projectList = jiraClient.getProjectClient().getAllProjects().get();
for (BasicProject proj : projectList) {
if (proj.getKey().equals("DEMO")) {
System.out.println("Found project: " + proj.getName());
} else {
System.out.println("Project not matching criteria");
}
}
// Search for issues using JQL
SearchResult searchResults = jiraClient.getSearchClient().searchJql("reporter = currentUser()").get();
for (BasicIssue ticket : searchResults.getIssues()) {
System.out.println("Issue found: " + ticket.getKey());
}
// Get specific issue details
Issue ticketDetails = jiraClient.getIssueClient().getIssue("DEMO-123").get();
System.out.println("Issue status: " + ticketDetails.getStatus().getName());
} finally {
jiraClient.close();
}
}
}
When I run this code, I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/atlassian/sal/api/executor/ThreadLocalContextManager
at com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory.create(AsynchronousJiraRestClientFactory.java:35)
at JiraClientDemo.main(JiraClientDemo.java:18)
Caused by: java.lang.ClassNotFoundException: com.atlassian.sal.api.executor.ThreadLocalContextManager
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
I’ve added the JIRA REST client JARs to my external libraries but I’m still getting this ClassNotFoundException. What dependencies am I missing and how should I properly configure my Gradle build file to include all necessary libraries for this to work?