Using Guice to Inject something in build (publish) steps

47 views
Skip to first unread message

Kirill Merkushev

unread,
Nov 23, 2015, 2:07:56 PM11/23/15
to Jenkins Developers
Hello!
 
I want to replace all static interactions in my plugin with DI.
 
But when i use @Inject annotation on @Extension class - all works perfectly, but with any kind of Describable (which should be created same as any extension i think) it doesn't work.
 
 
The main idea - that a want injected instance in perform method, but it only injected when i do Jenkins.getInstance().getInjector().injectMembers(this);
 
Can somebody help to clarify why this doesn't injected automatically?
 
Thanks!

Kanstantsin Shautsou

unread,
Nov 23, 2015, 2:17:24 PM11/23/15
to Jenkins Developers
cc (dunno how in google groups CC thread without post)

Jesse Glick

unread,
Nov 23, 2015, 2:22:33 PM11/23/15
to Jenkins Dev
On Mon, Nov 23, 2015 at 2:07 PM, Kirill Merkushev <twil...@gmail.com> wrote:
> when i use @Inject annotation on @Extension class - all works perfectly,
> but with any kind of Describable (which should be created same as any
> extension i think) it doesn't work.

`Describable`s are not singletons or extensions and cannot be used
with `@Inject`.

Kanstantsin Shautsou

unread,
Nov 23, 2015, 2:24:22 PM11/23/15
to jenkin...@googlegroups.com
Is it possible to create some @AutoWired and @Component spring analogues under jenkins code to not deal with constant Jenkins.get.. calls?
> --
> You received this message because you are subscribed to a topic in the Google Groups "Jenkins Developers" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/jenkinsci-dev/ZutbuAfl10s/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to jenkinsci-de...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr0%3DeH8_YhbB5M3aYGOcu70dmrnBA%2BSksc3C0DbJLKaBvA%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.

signature.asc

Jesse Glick

unread,
Nov 23, 2015, 2:24:36 PM11/23/15
to Jenkins Dev
Actually what you are trying to do has nothing to do with
`Describable`, but with `Builder`. At any rate, that does not work
either. DI in Jenkins is very limited. You can only wire extensions,
or `Jenkins`, to one another. If you want my opinion, you should not
bother with it at all.

Stephen Connolly

unread,
Nov 23, 2015, 2:29:56 PM11/23/15
to jenkin...@googlegroups.com
If you want a second opinion. You should not bother with even thinking about doing it at all.
--
You received this message because you are subscribed to the Google Groups "Jenkins Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-de...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-dev/CANfRfr1fC3mNOu9YYzqKrJPbPZX86pCuX%2B7H8JXEb43U5RHsJA%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.


--
Sent from my phone

Kirill Merkushev

unread,
Nov 23, 2015, 2:45:06 PM11/23/15
to Jenkins Developers
I've described only builder, but the question is about any describable (customized too).
Thanks for the quick answers!

It really sorry that i cant do it. It can simplify unit-testing a lot.

понедельник, 23 ноября 2015 г., 22:07:56 UTC+3 пользователь Kirill Merkushev написал:
Reply all
Reply to author
Forward
0 new messages