【问题标题】:atlassian plugin sdk: maven dependency not resolved for apache commonsatlassian 插件 sdk:没有为 apache commons 解析 maven 依赖项
【发布时间】:2017-12-11 10:24:20
【问题描述】:

我们一直致力于 JIRA 插件开发,并使用 apache-commons 库进行文件上传,如下所示:

<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.2</version>
<scope>provided</scope>
</dependency>

生成的插件在 atlas 开发环境中运行良好,但在 JIRA 上上传生成的 Jar 时,日志中显示以下错误。

 2017-12-11 09:49:53,841 UpmAsynchronousTaskManager:thread-3 
 ERROR jira.admin 357x1243x1 1ycla6b 14.102.4.74,13.58.31.162 /rest/plugins/1.0/ 
 [c.a.p.osgi.factory.OsgiPlugin] Detected an error (BundleException) enabling the plugin 'com.atlassian.tutorial.myPlugin' :
 Unresolved constraint in bundle com.atlassian.tutorial.myPlugin [237]: Unable to resolve 237.0: missing requirement [237.0] 
 osgi.wiring.package; (osgi.wiring.package=org.apache.commons.fileupload).  
 This error usually occurs when your plugin imports a package from another bundle with a specific version constraint and either the bundle providing that package doesn't meet those version constraints,
 or there is no bundle available that provides the specified package. For more details on how to fix this, see https://developer.atlassian.com/x/mQAN

在通过各种线程解决此问题后,我们尝试了以下方法。


  • 尝试使用不同版本的 Apache-Common 1.3.2 OR 1.3 OR 1.2.x 等...
  • 我们没有使用 maven,而是直接上传了 lib 文件夹中的 .jar 文件并更新了依赖项部分。 到目前为止,以上都没有奏效。

这是 POM.XML 文件:

<?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>com.atlassian.tutorial</groupId>
    <artifactId>myPlugin</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <organization>
        <name>Atlassian SDK Tutorial</name>
        <url>http://developer.atlassian.com/</url>
    </organization>
    <name>myPlugin</name>
    <description>This is the com.atlassian.tutorial:myPlugin plugin for Atlassian JIRA.</description>
    <packaging>atlassian-plugin</packaging>
    <dependencies>
        <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.activeobjects</groupId>
            <artifactId>activeobjects-plugin</artifactId>
            <version>1.2.3</version>
            <scope>provided</scope>
        </dependency>
       <!-- <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity-tools</artifactId>
            <version>1.3</version>
        </dependency>-->
        <!--<dependency>
            <groupId>info.bliki.wiki</groupId>
            <artifactId>bliki-core</artifactId>
            <version>3.0.19</version>
        </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>
        -->
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-all</artifactId>
            <version>1.8.5</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.6.6</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.1.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.4</version>
            <scope>provided</scope>
        </dependency>
        <!--<dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.3.2</version>
            <scope>provided</scope>
        </dependency>-->
        <dependency>
            <artifactId>commons-fileupload</artifactId>
            <groupId>commons-fileupload</groupId>
            <version>1.3.2</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/commons-fileupload-1.3.2.jar</systemPath>
            <extractDependencies>false</extractDependencies>
        </dependency>
        <dependency>
            <groupId>com.atlassian.templaterenderer</groupId>
            <artifactId>atlassian-template-renderer-api</artifactId>
            <version>1.3.1</version>
            <scope>provided</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><com class="atlassian tut"></com>orial.myPlugin.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>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <fork>true</fork>
                    <executable>C:\Program Files\Java\jdk1.8.0_151\bin\javac</executable>
                </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.5.0</jira.version>
        <amps.version>6.3.6</amps.version>
        <jdkLevel>1.8</jdkLevel>
        <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>
        <template.renderer.version>1.3.1</template.renderer.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
</project>

我们需要有关故障排除/解决上述问题的指导。

【问题讨论】:

    标签: java maven jira jira-plugin


    【解决方案1】:

    这看起来像一个 3rd 方库。所以你需要将你的范围从provided 更改为compile -

    <dependency>
    <groupId>commons-fileupload</groupId>
    <artifactId>commons-fileupload</artifactId>
    <version>1.3.2</version>
    <scope>compile</scope>
    </dependency>
    

    通过指定&lt;scope&gt;compile&lt;/scope&gt;,您告诉SDK 在编译时和运行时需要commons-fileupload 库。 SDK 会将 commons-fileupload 库捆绑到您的插件中,插件系统会在插件启动时使其在插件类加载器中可用。

    更多详情 - https://developer.atlassian.com/docs/getting-started/working-with-the-pom/managing-dependencies

    【讨论】:

    • 感谢您的上述回复。我们尝试使用以下选项: - 可选 - 提供 - 编译 但它不适用于以下任何选项。 JIRA 开发模式也是如此。
    • 有趣。您正在使用的其他库是否可能依赖于该库但版本不同?
    • 目前我们没有使用任何其他 3rd 方,但每当我们包含任何 3rd 方时,它都会给我们同样的错误。所以最终我们无法使用任何第 3 方,也无法使用任何特定的地方来进行故障排除。
    猜你喜欢
    • 2018-02-27
    • 2012-12-04
    • 2020-08-11
    • 1970-01-01
    • 2016-07-22
    • 2014-02-19
    • 2012-07-21
    • 2017-05-06
    • 1970-01-01
    相关资源
    最近更新 更多