Using external jars in Jira Plugin

I would like to use normal jars as dependencies for Jira Plugins. I tried the following:

  1. Download and install the newest Atlassian SDK.
  2. Created a new plugin with “atlas-create-jira-plugin”
  3. Added a dependency in the dependencies section of the pom. My example dependency is de.grammarcraft:de.grammarcraft.xtend.flow:0.5.0 . (http://search.maven.org/#artifactdetails|de.grammarcraft|de.grammarcraft.xtend.flow|0.5.0|jar)
  4. Started Jira with “atlas-run”. The plugin does not start.

I tried this on different computers, inside and outside the company network.

This also happens for other dependencies - with some, I need to really use a class in the source code to make it crash, for others, the dependency itself suffices.

I really want to understand if it is possible to add jars as dependencies (as in usual Java projects), or if I need to take another way. There are some company internal libraries that I need to use, and it would be great if I could access them from my Jira plugin.

Dear @fabian.meier,

adding dependencies via Maven normally work out of the box. And dependencies listed at Maven central do not even need a special configuration in the POM, like adding an additional repository.

Do you get any error messages from atlas-run, why the plugin is not starting? In order to check if the dependency got loaded correctly, take a look into the target/classes folder. There you should find the dependency in a subfolder, if everything was configured correctly.

Regards,
Alexander

The log is long and not easy to understand (at least for me), but the important part seems to be:

    ___ FAILED PLUGIN REPORT _____________________
    
    2 plugins failed to load during JIRA startup.
    
    	'de.continentale.testsvn.test-plugin-muv' - 'test-plugin-muv'  failed to load.
    		Cannot start plugin: de.continentale.testsvn.test-plugin-muv
    			Unresolved constraint in bundle de.continentale.testsvn.test-plugin-muv [176]: Unable to resolve 176.0: missing requirement [176.0] osgi.wiring.package; (osgi.wiring.package=sun.misc)
    
    		It was loaded from C:\devel\test-plugin-muv\target\jira\home\plugins\installed-plugins\test-plugin-muv-1.0.0-SNAPSHOT.jar
    
    	'de.continentale.testsvn.test-plugin-muv-tests' - 'test-plugin-muv'  failed to load.
    		Cannot start plugin: de.continentale.testsvn.test-plugin-muv-tests
    			Unresolved constraint in bundle de.continentale.testsvn.test-plugin-muv-tests [177]: Unable to resolve 177.0: missing requirement [177.0] osgi.wiring.package; (osgi.wiring.package=de.continentale.testsvn.api) [caused by: Unable to resolve 176.0: missing requirement [176.0] osgi.wiring.package; (osgi.wiring.package=sun.misc)]
    
    		It was loaded from C:\devel\test-plugin-muv\target\jira\home\plugins\installed-plugins\test-plugin-muv-1.0.0-SNAPSHOT-tests.jar

What are you importing?

The sun.misc package being imported seems strange (depending on what you’re importing - they might not be available in the jdk).

Would it be possible for you to paste your pom.xml? I’m mostly interested in your dependencies and the area.

I can add the pom for reference, but it is just the standard pom generated by “atlas-create-jira-plugin”, with the grammarcraft dependency added:

<?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>
    <groupId>de.continentale.testsvn</groupId>
    <artifactId>jira-test-2</artifactId>
    <version>1.0.0-SNAPSHOT</version>

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

    <name>jira-test-2</name>
    <description>This is the de.continentale.testsvn:jira-test-2 plugin for Atlassian JIRA.</description>
    <packaging>atlassian-plugin</packaging>

    <dependencies>
	
	    <dependency>
          <groupId>de.grammarcraft</groupId>
          <artifactId>de.grammarcraft.xtend.flow</artifactId>
          <version>0.5.0</version>
        </dependency>
  	
	
        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>jira-api</artifactId>
            <version>${jira.version}</version>
            <scope>provided</scope>
        </dependency>
        <!-- Add dependency on jira-core if you want access to JIRA implementation classes as well as the sanctioned API. -->
        <!-- This is not normally recommended, but may be required eg when migrating a plugin originally developed against JIRA 4.x -->
        <!--
        <dependency>
            <groupId>com.atlassian.jira</groupId>
            <artifactId>jira-core</artifactId>
            <version>${jira.version}</version>
            <scope>provided</scope>
        </dependency>
        -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>com.atlassian.plugin</groupId>
            <artifactId>atlassian-spring-scanner-annotation</artifactId>
            <version>${atlassian.spring.scanner.version}</version>
            <scope>compile</scope>
        </dependency>

        <dependency>
            <groupId>com.atlassian.plugin</groupId>
            <artifactId>atlassian-spring-scanner-runtime</artifactId>
            <version>${atlassian.spring.scanner.version}</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
            <scope>provided</scope>
        </dependency>

        <!-- WIRED TEST RUNNER DEPENDENCIES -->
        <dependency>
            <groupId>com.atlassian.plugins</groupId>
            <artifactId>atlassian-plugins-osgi-testrunner</artifactId>
            <version>${plugin.testrunner.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>jsr311-api</artifactId>
            <version>1.1.1</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.2.2-atlassian-1</version>
        </dependency>

        <!-- Uncomment to use TestKit in your project. Details at https://bitbucket.org/atlassian/jira-testkit -->
        <!-- You can read more about TestKit at https://developer.atlassian.com/display/JIRADEV/Plugin+Tutorial+-+Smarter+integration+testing+with+TestKit -->
        <!--
        <dependency>
            <groupId>com.atlassian.jira.tests</groupId>
            <artifactId>jira-testkit-client</artifactId>
            <version>${testkit.version}</version>
            <scope>test</scope>
        </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>
                    <!-- Uncomment to install TestKit backdoor in JIRA. -->
                    <!--
                    <pluginArtifacts>
                        <pluginArtifact>
                            <groupId>com.atlassian.jira.tests</groupId>
                            <artifactId>jira-testkit-plugin</artifactId>
                            <version>${testkit.version}</version>
                        </pluginArtifact>
                    </pluginArtifacts>
                    -->
                    <enableQuickReload>true</enableQuickReload>
                    <enableFastdev>false</enableFastdev>

                    <!-- See here for an explanation of default instructions: -->
                    <!-- https://developer.atlassian.com/docs/advanced-topics/configuration-of-instructions-in-atlassian-plugins -->
                    <instructions>
                        <Atlassian-Plugin-Key>${atlassian.plugin.key}</Atlassian-Plugin-Key>

                        <!-- Add package to export here -->
                        <Export-Package>
                            de.continentale.testsvn.api,
                        </Export-Package>

                        <!-- Add package import here -->
                        <Import-Package>
                            org.springframework.osgi.*;resolution:="optional",
                            org.eclipse.gemini.blueprint.*;resolution:="optional",
                            *
                        </Import-Package>

                        <!-- Ensure plugin is spring powered -->
                        <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>
        </plugins>
    </build>

    <properties>
        <jira.version>7.7.1</jira.version>
        <amps.version>6.3.15</amps.version>
        <plugin.testrunner.version>1.2.3</plugin.testrunner.version>
        <atlassian.spring.scanner.version>1.2.13</atlassian.spring.scanner.version>
        <!-- This key is used to keep the consistency between the key in atlassian-plugin.xml and the key to generate bundle. -->
        <atlassian.plugin.key>${project.groupId}.${project.artifactId}</atlassian.plugin.key>
        <!-- TestKit version 6.x for JIRA 6.x -->
        <testkit.version>6.3.11</testkit.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

</project>

If you whant your dependency to be added in the JAR file of your plugin so they will be available while running the plugin , I think you should set the option extractDependencies to false in your pom.xml

 <plugins>
            <plugin>
                <groupId>com.atlassian.maven.plugins</groupId>
                <artifactId>maven-jira-plugin</artifactId>
               ...
                <configuration>
                  ...
                     <extractDependencies>false</extractDependencies>
                  ...
                 </configuration>
         </plugin>
 </plugins>

hope this help.

3 Likes