Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Scriptrunner: Unable to resolve class when in file.

Tonje Stolpestad June 1, 2016

In an attempt to structure my code better than I had it before I have decided to use classes but now I have an issue with imports .My set up looks like this 

-mypackage

--ModifiedIssues.groovy (contains the class ModifiedIssuesHelper)

--ModifiedIssuesEndpoint.groovy (This will be a scriptrunner endpoint, for now it is just a script)

When I try to run ModifiedIssuesEndpoint.groovy in scriptrunner (using the console) I get the following errors:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
file:/C:/Users/tonje.stolpestad/scripts-repository/src/main/resources/mypackage/ModifiedIssuesEndpoint.groovy: 2: unable to resolve class mypackage.ModifiedIssuesHelper
 @ line 2, column 1.
   import mypackage.ModifiedIssuesHelper
   ^

1 error

The files are as follows:

//ModifiedIssuesEndpoint.groovy
package mypackage;
import com.atlassian.jira.issue.Issue;
import mypackage.ModifiedIssuesHelper

//Locally
private String userKey = "admin"
private String jqlSearch = "issuetype in (\"Work Package\", \"Master Change\")"

ModifiedIssuesHelper modifiedIssuesHelper = new ModifiedIssuesHelper();
List<Issue> issues = modifiedIssuesHelper.findIssues(userKey, jqlSearch);
List<Map> filteredIssues = modifiedIssuesHelper.filterIssues(issues);

log.debug filteredIssues;
//ModifiedIssues.groovyas
package mypackage

import ...

class ModifiedIssuesHelper {


    public List<Issue> findIssues(String userKey, String jqlSearch){...}
    public List<Map> filterIssues(List<Issue> issues){...}

}

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
JamieA
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.
June 1, 2016

When you are creating the endpoint, are you putting in just:

mypackage/ModifiedIssuesEndpoint.groovy

You should... I'm guess that C:/Users/tonje.stolpestad/scripts-repository/src/main/resources is not set as a scripts root. Script Console file tab shows you the script roots. You can set it using https://scriptrunner.adaptavist.com/latest/jira/#_script_roots.

Tonje Stolpestad June 1, 2016

I am getting these as script roots in the console tab: Available script roots are C:/Users/tonje.stolpestad/scripts-repository/src/main/resources/, C:\Users\tonje.stolpestad\scripts-repository\atlassian-apps\jira\amps-standalone\target\jira\home\scripts

And in the path to the file I am just entering mypackage/ModifiedIssuesEndpoint.groovy.

 

Tonje Stolpestad June 2, 2016

I tried to set up a test class for the ModifiedIssuesHelper and I got the same sort of unable to resolve  error there. That suggests to me that there is either something wrong with my packages or in the helpers class structure. What do you think @Jamie Echlin [Adaptavist]?

 

JamieA
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.
June 2, 2016

The class ModifiedIssuesHelper should be in a file: ModifiedIssuesHelper.groovy. It looks like it's in a different name? You can have multiple top-level classes in the same file in groovy, but can you rename it to see if that's the problem.

Tonje Stolpestad June 2, 2016

Hi. I have tried changing to that. I also tried making a new class in a new file and using that but I am getting the same error then. 

Tonje Stolpestad June 2, 2016

After some googling I saw a suggestion to remove the "!?*.groovy" in the complie settings in my IDE (IntelliJ) and this gives me a different issue. Now when I run the tests it says it can't find the class for the tests. I am not sure if this is a step in the right or wrong direction 

 

Tonje Stolpestad June 2, 2016

I did some more restructuring to try to fix the problem.

Now I have set up so that it is set up with 

-src 

--main/resources/mypackage/util/utilclass.groovy (where the class shares the name as the file)

--test/util/utilclasstest.groovy (which imports utilclass)

As mentioned above I removed the "!?*.groovy" in the compile settings. This means I can build and compile the project but when I try to run the test class I get "Class not found: "util.utilclasstest""

JamieA
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.
June 3, 2016

I'm lost now, there should be no need to compile it in IDEA.

JamieA
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.
June 3, 2016

If you're really not getting anywhere create a ticket at https://productsupport.adaptavist.com/servicedesk/customer/portal/2 and we can do a screenshare on Monday afternoon.

TAGS
AUG Leaders

Atlassian Community Events