[solved] impossible to inject ApplicationLinkService, plugin fails and delays bitbucket loading

Hi,

I just spent several hours trying to inject ApplicationLinkService so that I can access Jira REST API from Bitbucket Server. I’ve already fixed this but I’m leaving this note in-case anyone else gets stuck on this.

Scenario

  • Bitbucket plugin - generated today with Atlas 8.0.16/AMS 8.0.2
  • spring scanner 2
  • want to inject com.atlassian.applinks.api.ApplicationLinkService class annotated with @Named, constructor variable annotated with @ComponentImport
  • Other constructor injected variables working fine
  • Non-optional import of * in pom.xml
  • Dependency on com.atlassian.applinks:applinks-api in pom.xml

Problem
Bitbucket loading delayed ~5 minutes while it tries to resolve the constructor argument and logs flood with messages like this:

[INFO] 2019-08-02 20:48:54,809 INFO  [spring-startup]  com.atlassian.plugin.util.WaitUntil Plugins that have yet to be enabled: (2): [com.declarativesystems.bitbucket.xxx-tests, com.declarativesystems.bitbucket.xxx], 95 seconds remaining

Solution
There seem to be 3 things going on - I fixed all three at once so not sure if all of these are needed, the scope one definitely is though:

Wrong spring namespace
Generated project install a spring scanner 1x context file, although its pom.xml is setup for spring scanner 2, Eg namepace in src/main/resources/META-INF/spring/plugin-context.xml is

  xmlns:atlassian-scanner="http://www.atlassian.com/schema/atlassian-scanner"

But according to the spring scanner 2 docs it must be:

   xmlns:atlassian-scanner="http://www.atlassian.com/schema/atlassian-scanner/2"

Wrong version of applinks-api
I think I was just using the latest version but I’m really supposed to use the matching version from https://confluence.atlassian.com/display/APPLINKS052/Application+links+version+matrix

Wrong scope
I found the dependency for applinks using intellij and in my excitement completely forgot to add <scope>provided</scope> to the dependency… whoops!

With all the fixes in place the dependency gets injected right away and the plugin is enabled.