Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

ScriptRunner: Package Warning when Running Script from File

PeteToscano
Contributor
September 27, 2022

I have a couple Groovy scripts that one of my co-workers and I run every week to collect some Jira ticket stats. I recently had to tweak the script some for the Groovy 3.0 update in the ScriptRunner for Jira version 7.0 update. That was fixed and things looked, well, groovy.

Today, our SR4J install was updated to 7.1.0. Now when either script is run from file, I get this error (mod the script name):

  • /var/atlassian/application-data/jira/stats1.groovy:0 Expected class to be in package 'var.atlassian.application-data.jira' but found ''. This won't be supported in ScriptRunner 8.0. @ line 0, column 0.

If I take the contents of the file and paste it into Script Console under the Inline tab, the whole thing works fine with no warnings. 

I'm relatively new to Groovy and my Java knowledge stops around version 1.1, but from what I can tell, if I want to run the stats1.groovy script from file, I need to have some Package declaration at the start of the file.

I tried:

Package var.atlassian.application-data.jira

at the top since the warning said that that's what it was expecting. That lead to the interpreter thinking that I was trying to subtract "data.jira" from "var.atlassian.application" and subsequent errors for "var" and "data" being undeclared, some other errors, and then the warning from above, but this time instead of finding an empty string, it found 'var.atlassian.application'. 

Am I at least going down the right path here with using "Package"? I tried putting double and single quotation marks around the package name. I tried escaping the hyphen. Nothing worked. Is there some other way to tell the interpreter that '-' should be taken literally and not treated an an operator? Do I have to rearrange the container's directory structure to eliminate the warning? 

Looking at https://groovy-lang.org/syntax.html#_identifiers, I see that in section 3.1 that the identifiers like 'a-d' are invalid, but then in section 3.2 they talk about quoted identifiers, but I'm not sure how (or if) they can be applied to the Package name.

Ideas?

4 answers

1 accepted

1 vote
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
September 29, 2022

Hi @PeteToscano

Could you please share a screenshot of your Script Editor, i.e. like:-

script_editor.png

I am asking for this to understand how your packages are displayed.

Generally, the Groovy code files and packages should be added to the scripts/ folder, but I did not see it in your description.

Thank you and Kind regards,

Ram

Joshua Steubs October 17, 2022

Hi Ram,

 

We're having a similar issue. Our scripts are located in the scripts/ folder. This issue seemed to only appear once we updated from Scriptrunner 6.57-->7.2

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
October 17, 2022

Hi @Joshua Steubs

Could you please share a screenshot of your Script Edit, as shown in my previous comment?

Also, could you please try to repeat the steps in Safe-Mode, i.e. with all third-party plugins disabled except for ScriptRunner? This is to rule out if there is any issue associated with other third-party plugins.

Thank you and Kind regards,

Ram

Joshua Steubs October 27, 2022

Hi Ram,

 

Our JIRA admin wasn't willing to run in safe-mode. That being said, our issue seemed to "magically" get solved one day. My guess is that there was something misconfigured with the proxy in the new environment we migrated to, which got fixed at some point.  

0 votes
WW
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.
December 27, 2022

So, Adaptavist is now saying "Psych! Never mind."

They're no longer requiring "package" and are going to remove or change the message.

Why is there an Incorrect Package Declaration Message in the Script Editor?

Ram Kumar Aravindakshan _Adaptavist_
Community Champion
December 27, 2022

Hi @WW

The warning message will appear if you have given an incorrect package name that doesn't match the packages in which your groovy code is placed.

If your code is placed in the outermost folder, i.e. the scripts/ folder, then no package declaration is required.

However, if it is placed in other inner directories, for example, scripts/mock/, then your code must include the package name mock, for example:

package mock
....
....
....
def customFieldManager = ComponentAccessor.customFieldManager
....
....
....

Previously, this was not enforced in all the components except for the REST Endpoint.

But now, the warning message is included in all the components for best practices.

Thank you and Kind regards,

Ram

WW
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.
December 28, 2022

According to Why is there an Incorrect Package Declaration Message in the Script Editor?, there will still be a warning message but the package name will not be required.

If you have more than one script with the same name under different folders/packages, that's where the package name is needed, otherwise, ScriptRunner might point to the wrong one.

That page explicitly says:

there is no requirement to fix existing scripts, unless you want to

If that page is to be believed, you don't have to enter package <name> for every script, but it will warn you that you should. Nothing will be "enforced."

0 votes
Jeff Gordon
Contributor
October 27, 2022

We have added sub-folder structures under scripts such as script_behaviors, script_fields, script_listeners, etc. to organize and simplify.

So it looks like we will need to explicitly declare the sub-folder(s) as the package in each script residing in a sub-folder in preparation for SR 8.

Correct?

0 votes
PeteToscano
Contributor
October 18, 2022

Sorry for the delay, Ram. I had lost track of this thread for a while. 

Thank you for pointing out the need to put the Groovy scripts into the scripts folder. I copied the scripts into there and changed the path in the script field under the Console to just the script name. It run without warning, and it actually offered to autocomplete the script name. Not only that, but now the script editor seems to be working. Huzzah! 

Thanks, 
Ram

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.20.10
TAGS
AUG Leaders

Atlassian Community Events