BandanaManager - unresolved dependency

i am trying my hand at writing a bamboo plugin and i need to use bandana to store keys however with the latest SDK i am getting an unresolved dependency, looking at other plugin examples in github, this seems to be the only thing i need to do to use it via dependency injection. I have tried using
atlas-run (default 6.8) and also atlas-run -v 9.2.1

[INFO] [talledLocalContainer]
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘org.myorg.bamboo.TestPlugin’:
Unsatisfied dependency expressed through constructor argument with index 0 of type [com.atlassian.bandana.BandanaManager]: :
No qualifying bean of type [com.atlassian.bandana.BandanaManager] found for dependency:
expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations:
{}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.atlassian.bandana.BandanaManager]
found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}

import com.atlassian.bamboo.bandana.PlanAwareBandanaContext;
import com.atlassian.bamboo.configuration.GlobalAdminAction;
import com.atlassian.bandana.BandanaContext;
import com.atlassian.bandana.BandanaManager;
import org.apache.log4j.Logger;

public class TestPlugin extends GlobalAdminAction {
  private static final Logger log = Logger.getLogger(TestPlugin.class);
  
  private BandanaManager bandanaManager;
  
  public TestPlugin(final BandanaManager bandanaManager) {
    this.bandanaManager = bandanaManager;
  }

Looks like you are missing @ComponentImport to use bandanaManager.

Sample -

package com.vamhi.kali.impl;

import com.atlassian.plugin.spring.scanner.annotation.export.ExportAsService;
import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport;
import com.atlassian.sal.api.ApplicationProperties;
import com.vamhi.kali.api.MyPluginComponent;

import javax.inject.Inject;
import javax.inject.Named;

@ExportAsService ({MyPluginComponent.class})
@Named ("myPluginComponent")
public class MyPluginComponentImpl implements MyPluginComponent
{
        @ComponentImport
        private final ApplicationProperties applicationProperties;

        @Inject
        public MyPluginComponentImpl(final ApplicationProperties applicationProperties)
    {
        this.applicationProperties = applicationProperties;
    }

    public String getName()
    {
        if(null != applicationProperties)
        {
            return "myComponent:" + applicationProperties.getDisplayName();
        }
        
        return "myComponent";
    }
}
1 Like

Where are you getting that from, i have just downloaded the sdk, and created the plugin via the batch
atlas-create-bamboo-plugin and the template that is generated doesnt have that information in it

package org.myorg.bamboo.impl;

import com.atlassian.sal.api.ApplicationProperties;
import org.myorg.bamboo.api.MyPluginComponent;


public class MyPluginComponentImpl implements MyPluginComponent
{
        private final ApplicationProperties applicationProperties;

        public MyPluginComponentImpl(final ApplicationProperties applicationProperties)
    {
        this.applicationProperties = applicationProperties;
    }

    public String getName()
    {
        if(null != applicationProperties)
        {
            return "myComponent:" + applicationProperties.getDisplayName();
        }
        
        return "myComponent";
    }
}

I am using,

ATLAS Version:    8.2.7
ATLAS Home:       C:\Applications\Atlassian\atlassian-plugin-sdk-8.2.7
ATLAS Scripts:    C:\Applications\Atlassian\atlassian-plugin-sdk-8.2.7\bin
ATLAS Maven Home: C:\Applications\Atlassian\atlassian-plugin-sdk-8.2.7\apache-maven-3.5.4
AMPS Version:     8.1.2
--------
Executing: "C:\Applications\Atlassian\atlassian-plugin-sdk-8.2.7\apache-maven-3.5.4\bin\mvn.cmd" --version -gs C:\Applications\Atlassian\atlassian-plugin-sdk-8.2.7\apache-maven-3.5.4/conf/settings.xml
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-18T04:33:14+10:00)
Maven home: C:\Applications\Atlassian\atlassian-plugin-sdk-8.2.7\apache-maven-3.5.4\bin\..
Java version: 1.8.0_251, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk1.8.0_251\jre
Default locale: en_AU, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

Ok, i have found the issue. The plugin creation adds to the pom.xml, and the link that is supplied around the tag implies that it is required. however removing the block made the dependency injection work successfully

                    <!-- 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>
                            org.myorg.bamboo.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>