unable to resolve class com.atlassian.jira.ComponentManager

John Watson
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 10, 2019

Just upgraded to Jira 8.1.0 with Adaptavist ScriptRunner for JIRA 5.5.3.1-jira8

Suddenly our ScriptRunner Listeners are failing 100% of time with the following in the logs...

2019-04-10 11:11:16,957 http-nio-80-exec-18 ERROR gstegall 671x20674x1 18lp2y7 10.7.202.3 /secure/QuickEditIssue.jspa [c.o.scriptrunner.runner.AbstractScriptListener] Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script>
Script123.groovy: 1: unable to resolve class com.atlassian.jira.ComponentManager
2019-04-10 11:11:28,066 http-nio-80-exec-52 ERROR cpfeifer_aa 671x20732x1 10xp4ga 10.7.202.3 /secure/AssignIssue.jspa [c.o.scriptrunner.runner.AbstractScriptListener]

 

When I bring up the script in the editor, it also reports a syntax error on the very first import line for above component. 

Has anyone else experienced this issue?

8 answers

1 accepted

3 votes
Answer accepted
Ross McCoy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 11, 2019

ComponentManager has been deprecated since JIRA 7.11, which is the reason that you cannot resolve this class any longer.

You should migrate to using ComponentAccessor instead, and you may see the API documentation for this class here:

https://docs.atlassian.com/software/jira/docs/api/7.11.0/com/atlassian/jira/component/ComponentAccessor.html

If you have a specific example that uses ComponentManager, feel free to post it here and I'll be happy to show you how you can change it to use ComponentAccessor instead.

Colin Mack Nair April 18, 2019

How come when I try to import like this....
import com.atlassian.jira.component.ComponentAccessor

it tells me unable to resolve class com.atlassian.jira.component.ComponentAccessor?

Like # people like this
Richard Bone September 11, 2019

Here's a script I'm trying to use to convert tasks to sub-tasks but it implements the compoenentManager class. Could you convert it to use the ComponentAccessor?

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.security.Permissions
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.UpdateIssueRequest;

//Examples, 5 is my subtask issue type id. Will be different for others. Can find it in the issue history tab after converting a task to a sub-task
changeToSubTaskAndLink("XXX-8889", "XXX-0000", "5")

//Method to do all the work
def changeToSubTaskAndLink(parentId, childId, subTaskIssueTypeId)
{
//Get the parent Issue
def parent = ComponentManager.getInstance().getIssueManager().getIssueObject(parentId)
//Get the child Issue
def child = ComponentManager.getInstance().getIssueManager().getIssueObject(childId)
//Change the child to the subtask type
child.setIssueTypeId(subTaskIssueTypeId)
//Update the issue
ComponentAccessor.getIssueManager().updateIssue((ApplicationUser)ComponentManager.getInstance().jiraAuthenticationContext?.user,
(MutableIssue)child,
UpdateIssueRequest.builder().build())
//Create the subtask link, if this is not done you'll end up with orphans
ComponentAccessor.getSubTaskManager().createSubTaskIssueLink(parent,
child,
ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser())
}

Ashutosh Shrivastava October 29, 2020

I am using Jira 8.12.1 server version. My code already using componentaccessor and it was working fine with previous version of Jira 7.

But when we upgraded to 8.12.1 version, getting below error.

it tells me unable to resolve class com.atlassian.jira.component.ComponentAccessor?

However, import com.atlassian.jira.component.ComponentAccessor was working fine with Jira 7.

Even in Jira API document same package is mentioned. 

https://docs.atlassian.com/software/jira/docs/api/8.12.1/com/atlassian/jira/component/ComponentAccessor.html

Ajinkya Paradkar August 10, 2022

Hi @Ross McCoy  , We are upgrading Jira from version 6 to 7 and then to version 8 , the behaviors and listeners code is breaking when we reach the version 8.

 

Can I change the code in version 8 only or we need to change it in Jira 7 first and then upgrade to version 8 ?

Looking forward for your reply.

 

Thanks,

Ajinkya

0 votes
Adam Ziecik June 16, 2023

Hello @Ross McCoy 

I am trying to get this calculated field to work but I get 2 errors. Would you be able to help me change the script to work?

import
 
com.atlassian.jira.issue.Issue
import
 
com.atlassian.jira.issue.link.IssueLinkManager
import
 
com.atlassian.jira.issue.link.IssueLinkType
import
 
com.atlassian.jira.issue.link.IssueLinkTypeManager
import
 
com.atlassian.jira.ComponentManager
import
 
com.atlassian.jira.component.ComponentAccessor
import
 
com.atlassian.jira.jql.builder.JqlQueryBuilder
import
 
com.atlassian.jira.user.util.UserUtil
import
 
com.atlassian.jira.user.util.UserManager;
import
 
com.atlassian.jira.bc.issue.IssueService
import
 
com.atlassian.jira.bc.issue.search.SearchService;
import
 
com.atlassian.jira.issue.search.SearchProvider
import
 
com.atlassian.jira.issue.search.SearchResults
import
 
com.atlassian.jira.web.bean.PagerFilter;
import
 
com.atlassian.jira.issue.MutableIssue
import
 
com.atlassian.jira.user.UserPropertyManager
import
 
com.atlassian.jira.propertyset.JiraPropertySetFactory;
import
 
com.google.common.
collect
.ImmutableMap;
import
 
com.opensymphony.module.propertyset.PropertySet;
import
 
com.opensymphony.module.propertyset.PropertySetManager;
import
 
com.atlassian.jira.util.BuildUtils
import
 
com.atlassian.jira.util.BuildUtilsInfo
import
 
com.atlassian.jira.util.BuildUtilsInfoImpl
import
 
com.atlassian.plugin.PluginAccessor
import
 
com.atlassian.plugin.PluginManager
import
 
com.atlassian.jira.bc.license.JiraLicenseService
import
 
com.atlassian.jira.bc.license.JiraLicenseServiceImpl
import
 
org.apache.log4j.Level
import
 
org.apache.log4j.Logger
import
 
com.atlassian.jira.issue.IssueManager
 
 
Object getIssues(jqlQuery){
    
// A list of GenericValues representing issues
    
List<Issue> searchResults = 
null
;
 
    
SearchService.ParseResult parseResult =  searchService.parseQuery(serviceAccount, jqlQuery);
 
    
if
 
(parseResult.isValid()) {
        
// throws SearchException
        
SearchResults results = searchService.search(serviceAccount, parseResult.getQuery(), PagerFilter.getUnlimitedFilter());
        
searchResults = results.getIssues();
        
return
 
searchResults;
    
}
 
     
return
 
[]
}
 
projectManager = ComponentAccessor.getProjectManager()
componentManager = ComponentManager.getInstance();
searchService =  ComponentAccessor.getComponent(SearchService.
class
);
issueManager = ComponentAccessor.getIssueManager()
customFieldManager = ComponentAccessor.getCustomFieldManager()
userUtil = ComponentAccessor.getUserUtil();
serviceAccount = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
pluginAccessor = componentManager.getPluginAccessor();
 
IssueManager iManager = ComponentAccessor.getIssueManager();
Issue issue = issue;
 
jql = 
"issue in defectsCreatedForRequirement('${issue.key}')"
issues = getIssues(jql)
"<a href='/issues/?jql=issue%20in%20defectsCreatedForRequirement(${issue.key})'>${issues.size}</a>"

Errors:

The script could not be compiled:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script9.groovy: 5: unable to resolve class com.atlassian.jira.ComponentManager
@ line 5, column 1.
import com.atlassian.jira.ComponentManager
^

Script9.groovy: 25: unable to resolve class com.atlassian.plugin.PluginManager
@ line 25, column 1.
import com.atlassian.plugin.PluginManager
^

2 errors
.

0 votes
Hanna Torany January 19, 2022

I have a script that uses ComponentManager and needs to be converted to use ComponentAccessor instead. Can you help me?

 

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.link.IssueLinkTypeManager

def typeManager = (IssueLinkTypeManager)ComponentManager.getComponentInstanceOfType(IssueLinkTypeManager.class);
def linkCnt = 0
def duplicateLinkId = '10002'

request = webwork.action.ActionContext.getRequest()

if (issue.resolution?.name == "Duplicate") {
if (request) {
// check for new duplicates link
linktype = request.getParameter('issuelinks-linktype')
linkedIssue = request.getParameter('issuelinks-issues')
if (typeManager.getIssueLinkTypesByInwardDescription(linktype).id.toString().contains(duplicateLinkId) && linkedIssue) linkCnt = 1
}

// check for existing duplicates link
if ( issueLinkManager.getInwardLinks(issue.getId())*.issueLinkType.id.toString().contains(duplicateLinkId) ) linkCnt += 1

// Transition requires one, and only one, duplicates link
(linkCnt > 0)
} else {
return true
}

0 votes
Vasily Pupkin
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 16, 2021

PLS convert:

import com.atlassian.jira.ComponentManager

def componentManager = ComponentManager.getInstance()
def watcherManager = componentManager.getWatcherManager()
def userManager = componentManager.getUserUtil()

def watchUsers = {usernames ->
usernames.each {
def user = userManager.getUser(it)
watcherManager.startWatching(user, issue.getGenericValue())
}
}

def users = ["comma", "separated", "usernames"]
watchUsers(users)

0 votes
sandosh_vaidyanathan3 March 13, 2020

Can you help me convert this script?

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.portal.PortalPage
import com.atlassian.jira.portal.PortalPageManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.favourites.FavouritesManager
import org.apache.log4j.Logger
import org.apache.log4j.Level
def log = Logger.getLogger("")
log.setLevel(Level.DEBUG)
def portalPageIds = [10407,10404]
def groupNames = ['teq_jirasd_administrators']
def groupManager = ComponentAccessor.getGroupManager()

ComponentManager componentManager = ComponentManager.getInstance()
PortalPageManager portalPageManager = (PortalPageManager) componentManager.getComponentInstanceOfType(PortalPageManager.class)
FavouritesManager favouritesManager = (FavouritesManager) componentManager.getComponentInstanceOfType(FavouritesManager.class)

for (String groupName: groupNames) {
def grpUserList = groupManager.getUsersInGroup(groupName)
for (ApplicationUser user:grpUserList){
for (Long portalPageId: portalPageIds) {
PortalPage portalPage = portalPageManager.getPortalPageById(portalPageId)
try{
favouritesManager.addFavourite(user, portalPage)
log.info("Adding portal " + portalPageId.toString() + " to user: " + user)
} catch (Exception ex){
log.warn("Failed Adding portal " + portalPageId.toString() + " to user: " + user + "\n" + ex)
} //catch
} //for portalID
} //for group users
} //for groups

Ross McCoy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 14, 2020

I'll be happy to help if you can create a new question so you can mark it as the answer appropriately and others can then search for your question and benefit from the knowledge.

Like # people like this
0 votes
akashdeepsingh22
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 16, 2019
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueImpl
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue

boolean status = false

IssueManager issueManager = ComponentAccessor.getIssueManager()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
CustomField myCustomField1 = customFieldManager.getCustomFieldObjectByName("TestLead")
CustomField myCustomField2 = customFieldManager.getCustomFieldObjectByName("DesignLead")
String myCustomFieldVal1 = (String) issue.getCustomFieldValue(myCustomField1)
String myCustomFieldVal2 = (String) issue.getCustomFieldValue(myCustomField2)
if(myCustomFieldVal1.equals("Yes") && myCustomFieldVal2.equals("Yes"){
status = true
}
)
return status

 Can you please help me convert this. 

 

Thanks

0 votes
Anton Ermolaev November 1, 2019

Hi @Ross McCoy and other guys.

Please help with my short script that add comment in transition:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.comments.CommentManager
import com.opensymphony.workflow.WorkflowContext
import org.apache.log4j.Category

String currentUser = ((WorkflowContext) transientVars.get("context")).getCaller();
commmgr = (CommentManager) ComponentManager.getComponentInstanceOfType(CommentManager.class)
commmgr.create(issue, currentUser, "comment text", true)
issue.store()

Thanks 

Anton_Ermolaev November 15, 2019

self-fix ;)

import com.atlassian.jira.component.ComponentAccessor

def jiraAuthenticationContext = ComponentAccessor.getJiraAuthenticationContext();
def commentManager = ComponentAccessor.getCommentManager()
def user = jiraAuthenticationContext.getLoggedInUser()

commentManager.create(
issue,
user,
"comment text",
false)
0 votes
Daniel Miks May 27, 2019

I have a script that uses ComponentManager and needs to be converted to use ComponentAccessor instead.

 

// Script to consolidate values from multiple fields to a single field
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.customfields.view.CustomFieldParams
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.event.type.EventDispatchOption
import org.apache.log4j.Logger
import org.apache.log4j.Level

// Enable logging
def log = Logger.getLogger("com.jira.copyfieldcontent")
log.setLevel(Level.DEBUG)

// Managers
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def authContext = ComponentAccessor.getJiraAuthenticationContext();

// CustomField ID's
String FieldOneID = "customfield_10603"
String FieldTwoID = "customfield_10403"
String FieldThreeID = "customfield_13346"
String FieldFourID = "customfield_10601"

// DEBUG
//def issue = issueManager.getIssueByCurrentKey("SB-1")


// FieldOne
CustomField FieldOne = customFieldManager.getCustomFieldObject(FieldOneID)
String FieldOneValue = issue.getCustomFieldValue(FieldOne)
log.debug("FieldOneValue:" + FieldOneValue)

// FieldTwo
CustomField FieldTwo = customFieldManager.getCustomFieldObject(FieldTwoID)
String FieldTwoValue = issue.getCustomFieldValue(FieldTwo)
log.debug("FieldTwoValue:" + FieldTwoValue)

// Cascading Select Field
String FieldFourParent = ""
String FieldFourChild = ""
CustomField FieldFour = customFieldManager.getCustomFieldObject(FieldFourID)
Map FieldFourValue = issue.getCustomFieldValue(FieldFour) as Map
if (FieldFourValue) {
FieldFourParent = FieldFourValue.get(null)
FieldFourChild = FieldFourValue.get("1")
}

// Store in description
//String description = "FieldOneValue: " + FieldOneValue + "\n" + "FieldTwoValue: " + FieldTwoValue
//issue.description = description

// Store in FieldThree
String description = ""
description = description + "FieldOneValue: " + FieldOneValue + "\n"
description = description + "FieldTwoValue: " + FieldTwoValue + "\n"
description = description + "FieldFourParent: " + FieldFourParent + ", FieldFourChild: " + FieldFourChild +"\n"

log.debug("Description:" + description)
CustomField FieldThree = customFieldManager.getCustomFieldObject(FieldThreeID)
issue.setCustomFieldValue(FieldThree, description)
issueManager.updateIssue(authContext.getLoggedInUser(),issue, EventDispatchOption.DO_NOT_DISPATCH,false)

 

Can you please have a look at it?

Best Regards

Daniel Miks 

Ross McCoy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 27, 2019

Hello @Daniel Miks,

I saw that the script you posted imports com.atlassian.jira.ComponentManager, but I do not see where the ComponentManager is being used.

After migrating to Jira 8.0, this script will no longer function as the ComponentManager class has been removed. However, all that is needed to change in this script is to remove the import of the component manager. Take care that you don't confuse the ComponentManager class with other managers:

// Managers
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def authContext = ComponentAccessor.getJiraAuthenticationContext();

The above are not using the ComponentManager class - they are separate interfaces, accessed via ComponentAccessor. The ComponentManager class was historically used to access the manager interfaces like so:

ComponentManager componentManager = ComponentManager.getInstance();
delegator = (DelegatorInterface) componentManager.getComponentInstanceOfType(DelegatorInterface.class);

If you would like to make this a separate question so that others can benefit from this answer, you're welcome to do so and I can answer any further questions you have under that post. 

Like # people like this
Daniel Miks May 29, 2019

Hi @Ross McCoy and thank you for your answer.

Suggest an answer

Log in or Sign up to answer