ClassNotFoundException for jira-api classes in wired tests

Whenever I reference a class from the com.atlassian.jira.user package in my wire tests, I get ClassNotFoundException. For example, given the following code:

package it.com.acme;

import com.atlassian.jira.user.util.UserManager;
import com.atlassian.plugins.osgi.test.AtlassianPluginsTestRunner;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.Arrays;

@RunWith(AtlassianPluginsTestRunner.class)
public class MyITest {
    private final UserManager userManager;

    public MyITest(UserManager userManager) {
        this.userManager = userManager;
    }

    @Test
    public void shouldWork() {
        System.out.println("USER IS: " + userManager.getUserByKey("admin"));
        System.out.println("CLASS IS: " + userManager.getUserByKey("admin").getClass());
        System.out.println("INTERFACES: " + Arrays.toString(userManager.getUserByKey("admin").getClass().getInterfaces()));
        try {
            System.out.println("FORNAME " + Class.forName("com.atlassian.jira.user.ApplicationUser"));
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}

The output looks like:

[INFO] [talledLocalContainer] USER IS: admin(admin)
[INFO] [talledLocalContainer] CLASS IS: class com.atlassian.jira.user.DelegatingApplicationUser
[INFO] [talledLocalContainer] INTERFACES: [interface com.atlassian.jira.user.ApplicationUser]
[INFO] [talledLocalContainer] java.lang.ClassNotFoundException: com.atlassian.jira.user.ApplicationUser not found by com.acme.my-plugin-tests [285]

If the code has a “hard” dependency on ApplicationUser, the test blows up when loading the test class with NoClassDefFoundError.

What am I doing wrong? How can I solve it?

I found the solution. It seems to go away when I add Import-Package under bundle-instructions in atlassian-plugin.xml, like this:

    <plugin-info>
        <description>${project.description}</description>
        <version>${project.version}</version>
        <vendor name="${project.organization.name}" url="${project.organization.url}"/>
        <bundle-instructions>
            <Import-Package>com.atlassian.jira.user</Import-Package>
        </bundle-instructions>
    </plugin-info>

I ran into this too in the context of Confluence. The fix is apparently the same as documented here: https://developer.atlassian.com/server/framework/atlassian-sdk/classnotfoundexception/

I’m however not sure if this is the right solution to the issue. Wouldn’t it be better to use <component-import […] /> or Spring decorators to have the dependency being resolved? If not, is there any suggested read to better get accustomed to why this applies to the user package here while for other cases you’d use spring decorators/component-import?