Commons-fileupload dependency error

Hello,

I´m developing a new jira plugin and I need to add file upload functionality. I have started with commons-fileupload library but it doesn´t work.
Base on a basic plugin create with atlas-create-jira-plugin, without any modification I have added this dependency:

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

But the application give me this error when I try to upload the addon to jira

[INFO] [talledLocalContainer] com.atlassian.plugin.osgi.container.OsgiContainerException: Cannot start plugin: sample.file
[INFO] [talledLocalContainer] at com.atlassian.plugin.osgi.factory.OsgiPlugin.enableInternal(OsgiPlugin.java:418)
[INFO] [talledLocalContainer] at com.atlassian.plugin.impl.AbstractPlugin.enable(AbstractPlugin.java:287)
[INFO] [talledLocalContainer] at com.atlassian.plugin.manager.PluginEnabler.actualEnable(PluginEnabler.java:130)
[INFO] [talledLocalContainer] at com.atlassian.plugin.manager.PluginEnabler.enable(PluginEnabler.java:107)
[INFO] [talledLocalContainer] at com.atlassian.plugin.manager.DefaultPluginManager.enableDependentPlugins(DefaultPluginManager.java:1248)
[INFO] [talledLocalContainer] at com.atlassian.plugin.manager.DefaultPluginManager.addPlugins(DefaultPluginManager.java:1218)
[INFO] [talledLocalContainer] at com.atlassian.jira.plugin.JiraPluginManager.addPlugins(JiraPluginManager.java:165)
[INFO] [talledLocalContainer] at com.atlassian.plugin.manager.DefaultPluginManager.scanForNewPlugins(DefaultPluginManager.java:927)
[INFO] [talledLocalContainer] at com.atlassian.plugin.manager.DefaultPluginManager.installPlugins(DefaultPluginManager.java:845)
[INFO] [talledLocalContainer] at com.atlassian.jira.plugin.JiraPluginManager.installPlugins(JiraPluginManager.java:182)
[INFO] [talledLocalContainer] … 3 filtered
[INFO] [talledLocalContainer] at java.lang.reflect.Method.invoke(Method.java:498)
[INFO] [talledLocalContainer] at com.atlassian.plugin.util.ContextClassLoaderSettingInvocationHandler.invoke(ContextClassLoaderSettingInvocationHandler.java:26)
[INFO] [talledLocalContainer] at com.sun.proxy.$Proxy525.installPlugins(Unknown Source)
[INFO] [talledLocalContainer] … 3 filtered
[INFO] [talledLocalContainer] at java.lang.reflect.Method.invoke(Method.java:498)
[INFO] [talledLocalContainer] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)
[INFO] [talledLocalContainer] at org.eclipse.gemini.blueprint.service.importer.support.internal.aop.ServiceInvoker.doInvoke(ServiceInvoker.java:56)
[INFO] [talledLocalContainer] at org.eclipse.gemini.blueprint.service.importer.support.internal.aop.ServiceInvoker.invoke(ServiceInvoker.java:60)
[INFO] [talledLocalContainer] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
[INFO] [talledLocalContainer] at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)
[INFO] [talledLocalContainer] at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)
[INFO] [talledLocalContainer] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
[INFO] [talledLocalContainer] at org.eclipse.gemini.blueprint.service.util.internal.aop.ServiceTCCLInterceptor.invokeUnprivileged(ServiceTCCLInterceptor.java:70)
[INFO] [talledLocalContainer] at org.eclipse.gemini.blueprint.service.util.internal.aop.ServiceTCCLInterceptor.invoke(ServiceTCCLInterceptor.java:53)
[INFO] [talledLocalContainer] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
[INFO] [talledLocalContainer] at org.eclipse.gemini.blueprint.service.importer.support.LocalBundleContextAdvice.invoke(LocalBundleContextAdvice.java:57)
[INFO] [talledLocalContainer] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
[INFO] [talledLocalContainer] at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)
[INFO] [talledLocalContainer] at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)
[INFO] [talledLocalContainer] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
[INFO] [talledLocalContainer] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
[INFO] [talledLocalContainer] at com.sun.proxy.$Proxy1291.installPlugins(Unknown Source)
[INFO] [talledLocalContainer] at com.atlassian.upm.core.install.AbstractPluginInstallHandler$1.doInTransaction(AbstractPluginInstallHandler.java:139)
[INFO] [talledLocalContainer] at com.atlassian.upm.core.install.AbstractPluginInstallHandler$1.doInTransaction(AbstractPluginInstallHandler.java:134)
[INFO] [talledLocalContainer] at com.atlassian.sal.core.transaction.HostContextTransactionTemplate$1.doInTransaction(HostContextTransactionTemplate.java:21)
[INFO] [talledLocalContainer] at com.atlassian.jira.DefaultHostContextAccessor.doInTransaction(DefaultHostContextAccessor.java:36)
[INFO] [talledLocalContainer] … 2 filtered
[INFO] [talledLocalContainer] at java.lang.reflect.Method.invoke(Method.java:498)
[INFO] [talledLocalContainer] at com.atlassian.plugin.util.ContextClassLoaderSettingInvocationHandler.invoke(ContextClassLoaderSettingInvocationHandler.java:26)
[INFO] [talledLocalContainer] at com.sun.proxy.$Proxy135.doInTransaction(Unknown Source)
[INFO] [talledLocalContainer] … 2 filtered
[INFO] [talledLocalContainer] at java.lang.reflect.Method.invoke(Method.java:498)
[INFO] [talledLocalContainer] at com.atlassian.plugin.osgi.bridge.external.HostComponentFactoryBean$DynamicServiceInvocationHandler.invoke(HostComponentFactoryBean.java:136)
[INFO] [talledLocalContainer] at com.sun.proxy.$Proxy135.doInTransaction(Unknown Source)
[INFO] [talledLocalContainer] at com.atlassian.sal.core.transaction.HostContextTransactionTemplate.execute(HostContextTransactionTemplate.java:18)
[INFO] [talledLocalContainer] … 2 filtered
[INFO] [talledLocalContainer] at java.lang.reflect.Method.invoke(Method.java:498)
[INFO] [talledLocalContainer] at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302)
[INFO] [talledLocalContainer] at org.eclipse.gemini.blueprint.service.importer.support.internal.aop.ServiceInvoker.doInvoke(ServiceInvoker.java:56)
[INFO] [talledLocalContainer] at org.eclipse.gemini.blueprint.service.importer.support.internal.aop.ServiceInvoker.invoke(ServiceInvoker.java:60)
[INFO] [talledLocalContainer] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
[INFO] [talledLocalContainer] at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)
[INFO] [talledLocalContainer] at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)
[INFO] [talledLocalContainer] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
[INFO] [talledLocalContainer] at org.eclipse.gemini.blueprint.service.util.internal.aop.ServiceTCCLInterceptor.invokeUnprivileged(ServiceTCCLInterceptor.java:70)
[INFO] [talledLocalContainer] at org.eclipse.gemini.blueprint.service.util.internal.aop.ServiceTCCLInterceptor.invoke(ServiceTCCLInterceptor.java:53)
[INFO] [talledLocalContainer] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
[INFO] [talledLocalContainer] at org.eclipse.gemini.blueprint.service.importer.support.LocalBundleContextAdvice.invoke(LocalBundleContextAdvice.java:57)
[INFO] [talledLocalContainer] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
[INFO] [talledLocalContainer] at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)
[INFO] [talledLocalContainer] at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)
[INFO] [talledLocalContainer] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
[INFO] [talledLocalContainer] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208)
[INFO] [talledLocalContainer] at com.sun.proxy.$Proxy1331.execute(Unknown Source)
[INFO] [talledLocalContainer] at com.atlassian.upm.core.install.AbstractPluginInstallHandler.installArtifacts(AbstractPluginInstallHandler.java:133)
[INFO] [talledLocalContainer] at com.atlassian.upm.core.install.AbstractPluginInstallHandler.installArtifact(AbstractPluginInstallHandler.java:119)
[INFO] [talledLocalContainer] at com.atlassian.upm.core.install.JarPluginInstallHandler.installPluginInternal(JarPluginInstallHandler.java:52)
[INFO] [talledLocalContainer] at com.atlassian.upm.core.install.AbstractPluginInstallHandler.installPlugin(AbstractPluginInstallHandler.java:60)
[INFO] [talledLocalContainer] at com.atlassian.upm.core.install.DefaultPluginInstallationService.execute(DefaultPluginInstallationService.java:117)
[INFO] [talledLocalContainer] at com.atlassian.upm.core.install.DefaultPluginInstallationService.install(DefaultPluginInstallationService.java:91)
[INFO] [talledLocalContainer] at com.atlassian.upm.install.UpmPluginInstallationService.install(UpmPluginInstallationService.java:97)
[INFO] [talledLocalContainer] at com.atlassian.upm.core.rest.resources.install.InstallTask.installFromFile(InstallTask.java:156)
[INFO] [talledLocalContainer] at com.atlassian.upm.core.rest.resources.install.InstallFromFileTask.executeTask(InstallFromFileTask.java:37)
[INFO] [talledLocalContainer] at com.atlassian.upm.core.rest.resources.install.InstallTask.run(InstallTask.java:81)
[INFO] [talledLocalContainer] at com.atlassian.upm.core.async.AsynchronousTaskManager.executeTask(AsynchronousTaskManager.java:124)
[INFO] [talledLocalContainer] at com.atlassian.upm.core.async.AsynchronousTaskManager$1.call(AsynchronousTaskManager.java:102)
[INFO] [talledLocalContainer] at com.atlassian.upm.core.async.AsynchronousTaskManager$1.call(AsynchronousTaskManager.java:99)
[INFO] [talledLocalContainer] at com.atlassian.sal.core.executor.ThreadLocalDelegateCallable.call(ThreadLocalDelegateCallable.java:38)
[INFO] [talledLocalContainer] at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[INFO] [talledLocalContainer] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[INFO] [talledLocalContainer] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[INFO] [talledLocalContainer] at java.lang.Thread.run(Thread.java:748)
[INFO] [talledLocalContainer] Caused by: org.osgi.framework.BundleException: Unresolved constraint in bundle sample.file [214]: Unable to resolve 214.0: missing requirement [214.0] osgi.wiring.package; (osgi.wiring.package=javax.portlet)
[INFO] [talledLocalContainer] at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:3974)
[INFO] [talledLocalContainer] at org.apache.felix.framework.Felix.startBundle(Felix.java:2037)
[INFO] [talledLocalContainer] at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955)
[INFO] [talledLocalContainer] at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:942)
[INFO] [talledLocalContainer] at com.atlassian.plugin.osgi.factory.OsgiPlugin.enableInternal(OsgiPlugin.java:399)
[INFO] [talledLocalContainer] 2019-01-25 06:59:31,875 UpmScheduler:thread-2 WARN admin [c.a.upm.pac.PacClientImpl] Update check request may take longer because of the number of add-ons
[INFO] [talledLocalContainer] 2019-01-25 06:59:32,620 http-nio-2990-exec-12 WARN admin 419x4067x1 1wnx5os 0:0:0:0:0:0:0:1 /rest/plugins/1.0/installed-marketplace [c.a.upm.pac.PacClientImpl] Update check request may take longer because of the number of add-ons

I have tried to change the version for a old one, but with the same results.
I can not change the compile scope because not all the jira versions has this library bundle and it has to been with the plugin.
Does anyone know any solution?
Or can I use another library to upload files?
Thank you

UPDATED: with Dennis solution

I stumbled upon this error too in Jira 8. What I did was adding the portlet-api as depencency and importing it in OSGI:

        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.4</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>javax.portlet</groupId>
            <artifactId>portlet-api</artifactId>
            <version>1.0</version>
            <scope>compile</scope>
        </dependency>

...

                    <instructions>
                        <Atlassian-Plugin-Key>${atlassian.plugin.key}</Atlassian-Plugin-Key>
                        <Export-Package>my.app.api</Export-Package>
                        <Import-Package>
                            com.atlassian.sal.*,
                            !javax.portlet.*,
                            !org.apache.commons.fileupload.*,
                            *
                        </Import-Package>
                        <Spring-Context>*</Spring-Context>
                    </instructions>

Good Things to read:

1 Like

Hi @clouless,

I’m not sure if this is a good solution. resolution:="required" is at least not supported by OSGI 7. Essentially, this solution appears to be undefined behavior. A better solution would be to prevent the import (because you’re bundling the library with your app). This can be achieved by writing (e.g): !javax.portlet.*

1 Like

ok thanks for the info :slight_smile: I will try your solution

I’m using portlet-api with provided scope and then I use

;javax.portlet.;resolution:=“optional”,