Following https://developer.atlassian.com/bamboodev/bamboo-tasks-api/executing-external-processes-using-processservice I would like to invoke some command using ProcessService bean. The injection as described in the link, does not work.
I checked the source of several other plugins at Bitbucket, but each is using the concept as described in the link.
My class:
... import com.atlassian.bamboo.process.ProcessService; ... public class CheckTask implements TaskType { private final ProcessService processService; public CheckTask(@NotNull final ProcessService processService) { this.processService = processService; }
However Bamboo does not find the ProcessService bean and fail with following:
(org.springframework.beans.factory.UnsatisfiedDependencyException : Error creating bean with name 'bamboo.tasks.CheckTask': Unsatisfied dependency expressed through constructor argument with index 0 of type [com.atlassian.bamboo.process.ProcessService]: : No qualifying bean of type [com.atlassian.bamboo.process.ProcessService] 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.bamboo.process.ProcessService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {})
Am I missing something ?
Bamboo version: 5.13.0
AMPS version: 6.2.6
Community moderators have prevented the ability to post new answers.
The solution in the end was quite simple, no oficial docs discuss the solution though. Hope this helps you a bit.
Finally thanks to this post I made it work:https://answers.atlassian.com/questions/33141765/testcollationservice-not-injected-into-tasktype-constructor-on-sdk-bamboo
import com.atlassian.bamboo.process.ProcessService; import com.atlassian.plugin.spring.scanner.annotation.component.Scanned; import com.atlassian.plugin.spring.scanner.annotation.imports.ComponentImport; @Scanned public class CheckTask implements TaskType { @ComponentImport private final ProcessService processService; public CheckTask(@NotNull final ProcessService processService) { this.processService = processService; }
The rest of the project was basicaly default, as generated by atlas-create-bamboo-plugin.
Using atlassian-spring-scanner (annotations Scanned and ComponentImport) is preferred way to do it. You might also use field injection and skip constructor altogether:
@Autowired @ComponentImport private ProcessService processService;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Using injection on private fields is discouraged, as it is hiding dependencies and makes testing more complicated etc. http://olivergierke.de/2013/11/why-field-injection-is-evil/ or https://www.petrikainulainen.net/software-development/design/why-i-changed-my-mind-about-field-injection/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
WRT testing: Mockito handles injection on private fields pretty well (but I agree that it is more straightforward when you use constructor injection).
Also if my dependencies are marked with dedicated annotation then how can you say I'm hiding them?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Private fields are not public API, that is what I mean by hiding. You have to check someone elses source code to check for the deps, which is also not always possible. Of course, we've got decompilers .. but ... If all mandatory dependencies are part of the constructor, you just can't miss them. See what I mean? But I guess this is a topic for a different place . Thanks for help. Cheers!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Downloaded your SDK few days ago and generated my plugin using the atlas-create-bamboo-plugin. That version was generated by that command inside the pom.xml.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How do you use unreleased Bamboo version, 5.13.0 is coming at the end of August 2016.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Do you have component-import of ProcessService in atlassian-plugin.xml?
<component-import key="processService" interface="com.atlassian.bamboo.process.ProcessService" />
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your help, I tried that one. The plugin build then unfortunately fails with: atlassian-plugin.xml contains a definition of component-import. This is not allowed when Atlassian-Plugin-Key is set.
The Atlassian-Plugin-Key part was generated by the atlas-create-bamboo-plugin.
I have found another solution though. Will post the answer right away.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.