Importing jars into script plugin

Mathew B September 3, 2019

I was creating a script plugin and it seems like my script doesn't have access to any of the jars declared in my POM.

 

We were previously just hand bombing jars into the WEB-INF/lib folder but this method leaves a lot to be desired. We would prefer to have a more automated style, like using the POM system.

 

Whats the "official" way to import jars for use in scripts?

 

Thanks

2 answers

1 accepted

0 votes
Answer accepted
Mathew B September 6, 2019

I've found my issue.

 

This issue was stemming from using the newest scriptrunner plugin version, I've spoken to adapavist and they've advised to use version 13 as 14 and 15 both have bugs.

 

I appreciate the help @Rafael Pinto Sperafico 

1 vote
Rafael Pinto Sperafico
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.
September 4, 2019

Hi @Mathew B ,

You should be looking at Maven Repositories:

Once you have your pom.xml or settings.xml configured with <repositories>, then you can simply refer to a <dependency> in your pom.xml

More information on https://developer.atlassian.com/server/framework/atlassian-sdk/working-with-maven/

Kind regards,
Rafael

Mathew B September 4, 2019

Hello @Rafael Pinto Sperafico

I appreciate the quick reply! 

 

I’ve configured my POM file to import the dependencies but they don’t seem to be available within the class path of my groovy function. 

With a normal plugin I’ve gotten my dependencies to work however with creating a script plugin with script runner it doesn’t my groovy scripts cannot import them. 

Rafael Pinto Sperafico
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.
September 4, 2019

Hi @Mathew B ,

If you are using an IDE, please check which Maven your project or IDE is configured with. Depending on the IDE you can also define which settings.xml the IDE will be relying on.

Screenshot 2019-09-04 at 19.51.54.png

In screenshot above, you can see IntelliJ IDEA Maven configuration.

Please, make sure you IDE is pointing to the places it is supposed to so it can get the dependencies from the repositories you have configured in settings.xml

Is is possible to share your pom.xml and settings.xml for review?

Kind regards,
Rafael

Mathew B September 4, 2019

hello @Rafael Pinto Sperafico ,

I’ve been following this tutorial on creating a script plugin. I know it’s outdated with some of the dependencies but just using it as a starting place. 

https://community.atlassian.com/t5/Jira-articles/Part-1-How-to-deploy-Adaptivist-ScriptRunner-scripts-and-objects/ba-p/794887

My pom file is really close to the one in the tutorial but here’s mine 

 

<?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/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<!--
I added the parent pom.xml, which does all the magic. I took this pom.xml from the ScriptRunner sample plugin
-->
<parent>
<groupId>com.adaptavist.pom</groupId>
<artifactId>scriptrunner-jira-standard</artifactId>
<version>15</version>
<relativePath/>
</parent>

<groupId>ru.matveev.alexey.scriptrunner</groupId>
<artifactId>scriptrunner-plugin</artifactId>
<version>1.0.0-SNAPSHOT</version>

<organization>
<name>Example Company</name>
<url>http://www.example.com/</url>
</organization>

<name>scriptrunner-plugin</name>
<description>This is the ru.matveev.alexey.scriptrunner:scriptrunner-plugin plugin for Atlassian JIRA.</description>
<packaging>atlassian-plugin</packaging>

<dependencies>
<!--
I excluded a couple of dependencies from the dependency below, because the plugin did not want to start for ScriptRunner versions higher than 5.3.0
-->
<dependency>
<groupId>com.onresolve.jira.groovy</groupId>
<artifactId>groovyrunner</artifactId>
<version>${scriptrunner.version}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>com.onresolve.scriptrunner.platform</groupId>
<artifactId>scriptrunner-test-libraries-jira</artifactId>
</exclusion>
<exclusion>
<groupId>jndi</groupId>
<artifactId>jndi</artifactId>
</exclusion>
<exclusion>
<groupId>jta</groupId>
<artifactId>jta</artifactId>
</exclusion>
<exclusion>
<groupId>is.origo.jira</groupId>
<artifactId>tempo-plugin</artifactId>
</exclusion>
<exclusion>
<groupId>com.tempoplugin</groupId>
<artifactId>tempo-core</artifactId>
</exclusion>
<exclusion>
<groupId>groovyrunner</groupId>
<artifactId>test</artifactId>
</exclusion>
<exclusion>
<groupId>com.atlassian.plugin.automation</groupId>
<artifactId>automation-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-annotation</artifactId>
<version>${atlassian.spring.scanner.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.riadalabs.jira.plugins</groupId>
<artifactId>insight</artifactId>
<version>8.0.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.riadalabs</groupId>
<artifactId>insight-core-model</artifactId>
<version>0.2.2</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>com.skyfoundry.haystack</groupId>
<artifactId>haystack-java</artifactId>
<version>1.0</version>
</dependency>


</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-jira-plugin</artifactId>
<version>${amps.version}</version>
<extensions>true</extensions>
<configuration>
<productVersion>${jira.version}</productVersion>
<productDataVersion>${jira.version}</productDataVersion>
<!--
I added Jira Software to the plugin because I want Jira Software to start on the atlas-run command.
-->
<applications>
<application>
<applicationKey>jira-software</applicationKey>
<version>${jira.version}</version>
</application>
</applications>
<instructions>
<Atlassian-Plugin-Key>${atlassian.plugin.key}</Atlassian-Plugin-Key>
<Export-Package>
ru.matveev.alexey.scriptrunner.api,
</Export-Package>
<Import-Package>
org.springframework.osgi.*;resolution:="optional",
org.eclipse.gemini.blueprint.*;resolution:="optional",
*
</Import-Package>
<Spring-Context>*</Spring-Context>
</instructions>
</configuration>
</plugin>

<plugin>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-maven-plugin</artifactId>
<version>${atlassian.spring.scanner.version}</version>
<executions>
<execution>
<goals>
<goal>atlassian-spring-scanner</goal>
</goals>
<phase>process-classes</phase>
</execution>
</executions>
<configuration>
<scannedDependencies>
<dependency>
<groupId>com.atlassian.plugin</groupId>
<artifactId>atlassian-spring-scanner-external-jar</artifactId>
</dependency>
</scannedDependencies>
<verbose>false</verbose>
</configuration>
</plugin>
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-jira-plugin</artifactId>

<configuration>
<httpPort>2990</httpPort>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<jira.version>8.0.2</jira.version>
<jira.servicedesk.application.version>3.12.0</jira.servicedesk.application.version>
<scriptrunner.version>5.6.1.1-jira8</scriptrunner.version>
<amps.version>6.3.21</amps.version>
<plugin.testrunner.version>1.2.3</plugin.testrunner.version>
<atlassian.spring.scanner.version>2.0.0</atlassian.spring.scanner.version>
<atlassian.plugin.key>${project.groupId}.${project.artifactId}</atlassian.plugin.key>
<testkit.version>6.3.11</testkit.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<repositories>
<!--
This is required to find the parent pom and ScriptRunner dependencies
-->
<repository>
<id>adaptavist-external</id>
<url>https://nexus.adaptavist.com/content/repositories/external</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
<checksumPolicy>fail</checksumPolicy>
</releases>
</repository>
</repositories>
</project>

 

Im not using an IDE since I’m working over ssh. Maven is getting the jars just fine, it’s just that they don’t seem to be in the class path of my plugin. 

Rafael Pinto Sperafico
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.
September 4, 2019

Hi @Mathew B ,

I was experiencing some issues with ScriptRunner v5.6.1.1-jira8 the other day where I was attempting on packing my groovy script into a JAR file and deploy them to Jira.

To be more specified, when running jira:debug, I was setting up my groovy script(s) in the ScriptRunner Listeners sections, then running the Configuration exporter to update scriptrunner.yaml.

When package was called and a JAR was generated, by installing the JAR file on a standalone Jira instance, I was unable to see the groovy scripts installed, furthermore, I was unable to select the groovy script from the JAR file because ScriptRunner was looking for scripts under <JIRA_HOME>/scripts folder.

If you run from your ScriptRunner project jira:debug, do you see your groovy scripts executing accordingly or is it just when creating a JAR file and installing it into a Jira standalone instance the issue happens?

Perhaps you should consider raising a support request with Adaptavist explaining them issue you are experiencing and ask for assistance. You can find support details from ScriptRunner for Jira

Kind regards,
Rafael

Mathew B September 4, 2019

I’ve started from scratch again and I’m having any issue even getting the default script plugin to load correctly. It keeps saying that it cannot start the plugin once uploaded. 

 

Edit: okay I see this plugin thing is normal with the script plugin. I still cannot load jars though. 

Suggest an answer

Log in or Sign up to answer