Spring scanner 2: PluginUpgradeTask not running

I am trying to create a PluginUpgradeTask, which shall create some issue types upon installation of the plugin, if these issues types are not already present. I am using spring scanner 2.

abstract class AbstractUpgradeTask implements PluginUpgradeTask {
    @Override
    public String getPluginKey() {
        Bundle bundle = FrameworkUtil.getBundle(AbstractUpgradeTask.class);
        String key = OsgiHeaderUtil.getPluginKey(bundle);
        return key;
    }
}
@ExportAsService(CreateIssueTypesUpgradeTask.class)
@Component
public class CreateIssueTypesUpgradeTask extends AbstractUpgradeTask {

    private static final Logger log = LoggerFactory.getLogger(CreateIssueTypesUpgradeTask.class);

    @JiraImport
    private IssueTypeManager issueTypeManager;

    @Autowired
    public CreateIssueTypesUpgradeTask(IssueTypeManager issueTypeManager) {
        this.issueTypeManager = issueTypeManager;
        log.debug("CreateIssueTypesUpgradeTask created");
    }

    /**
     * @return The new build number that this upgrade will upgrade to
     * Build number is specified in atlassian-plugin.xml inside &lt;plugin-info&gt; element. eg: <code>&lt;param name="build"&gt;1&lt;/param&gt;</code>
     */
    @Override
    public int getBuildNumber() {
        return 0;
    }

    /**
     * @return A short (under 50 chars) description of the upgrade action
     */
    @Override
    public String getShortDescription() {
        return "Creates the issue types.";
    }

    /**
     * Perform the upgrade task. An exception should be thrown if the upgrade fails and cannot be recovered from. A
     * collection of error or warning messages should be returned if there a problems with the upgrade that are not
     * severe enough to halt the execution of the entire upgrade process. An exception should be thrown if the upgrade
     * process cannot continue.
     *
     * @return a collection of warnings about the upgrade
     * @throws Exception if the upgrade fails
     */
    @Override
    public Collection<Message> doUpgrade() throws Exception {
        log.debug("CreateIssueTypesUpgradeTask doUpgrade()");
        boolean hasTypeDepartment = false, hasTypeTeam = false, hasTypeTest = false;
        Collection<IssueType> types = issueTypeManager.getIssueTypes();
        for (IssueType type : types) {
            if (type.getName().equalsIgnoreCase("Department")) {
                hasTypeDepartment = true;
            } else if (type.getName().equalsIgnoreCase("Team")) {
                hasTypeTeam = true;
            } else if (type.getName().equalsIgnoreCase("Test")) {
                hasTypeTest = true;
            }
        }
        if (!hasTypeDepartment) {
            IssueType bcmIssueType = issueTypeManager.createIssueType("Department", "Issue type for department", 10500L);
        } else {
            log.debug("IssueType 'Department' already exists");
        }
        if (!hasTypeTeam) {
            IssueType bcmTeamIssueType = issueTypeManager.createIssueType("Team", "Issue type for team", 10509L);
        } else {
            log.debug("IssueType 'Team' already exists");
        }
        if (!hasTypeTest) {
            IssueType bcmTestIssueType = issueTypeManager.createIssueType("Test", "Issue type for test", 10516L);
        } else {
            log.debug("IssueType 'Test' already exists");
        }

        return Collections.emptyList();
    }
}

The problem is that the PluginUpgradeTask seems not to be running. I can see the “CreateIssueTypesUpgradeTask created” output in the logs, but it seems the doUpgrade() method is not called. I already increased the buildnumber several times, but it had no effect. I can’t see the debugging output inside the doUpgrade() in the logs, only the output from the constructor.
Also in the propertyentry database table there is no entry for my PluginUpgradeTask, so it seems that is has not run once.

What am I missing?

It should be exported as

@ExportAsService(PluginUpgradeTask.class)

Thank you! It worked :slight_smile: