@JenkinsRule plugin list customisation

22 views
Skip to first unread message

Radek Antoniuk

unread,
Oct 23, 2020, 7:30:39 AM10/23/20
to Jenkins Developers
In the context of
how can I customise the list of plugins that the test runs with to detect a missing dependency in tests?

but there is no @WithoutPlugin and it seems that JenkinsRule somehow installs credentials plugin even though it is not mentioned in pom.xml.
I suppose it is using "Suggested plugins list" but I couldn't find it anywhere in JenkinsRule class..

Btw - how can I find easily the corresponding jenkins.io/doc/ of a specific page on the old docs - e.g. https://wiki.jenkins.io/display/JENKINS/Unit+Test#UnitTest-@WithPlugin(NameOfPlugin)
Can the links to the new site be automatically or manually added ?

Cheers,
Radek

Radosław Antoniuk

unread,
Oct 23, 2020, 7:33:08 AM10/23/20
to jenkin...@googlegroups.com
Whoops, the context link got deleted. 

Jesse Glick

unread,
Oct 23, 2020, 8:27:33 AM10/23/20
to Jenkins Dev
On Fri, Oct 23, 2020 at 7:30 AM Radek Antoniuk <radek.a...@gmail.com> wrote:
> how can I customise the list of plugins that the test runs with

Normally you do not do anything besides have plugins of interest in
your Maven test classpath. `@WithPlugin` is tricky and rarely needed.

> to detect a missing dependency in tests?

What specifically are you trying to accomplish? Reproducing
JENKINS-64002 in a test? Not going to work (see JENKINS-41827). Your
mistake can be seen from `mvn dependency:tree`:

[INFO] +- org.jenkins-ci.plugins:p4:jar:1.3.8:compile (optional)
[INFO] | +- org.jenkins-ci.plugins:credentials:jar:2.3.13:compile (optional)

You explicitly use the `credentials` plugin’s APIs, so you should have
a direct dependency on it. (check `mvn dependency:analyze`)

In general, use `optional` dependencies only with extreme care; see
JENKINS-19508 for discussion.

BTW your plugin does not build in `master`, perhaps because #277
introduced a mistake that #290 caught, or similar.

Radosław Antoniuk

unread,
Oct 23, 2020, 1:00:21 PM10/23/20
to jenkin...@googlegroups.com
On Fri, Oct 23, 2020 at 2:27 PM Jesse Glick <jgl...@cloudbees.com> wrote:
On Fri, Oct 23, 2020 at 7:30 AM Radek Antoniuk <radek.a...@gmail.com> wrote:
> how can I customise the list of plugins that the test runs with

Normally you do not do anything besides have plugins of interest in
your Maven test classpath. `@WithPlugin` is tricky and rarely needed.

> to detect a missing dependency in tests?

What specifically are you trying to accomplish? Reproducing
JENKINS-64002 in a test? Not going to work (see JENKINS-41827). Your
mistake can be seen from `mvn dependency:tree`:

[INFO] +- org.jenkins-ci.plugins:p4:jar:1.3.8:compile (optional)
[INFO] |  +- org.jenkins-ci.plugins:credentials:jar:2.3.13:compile (optional)


You explicitly use the `credentials` plugin’s APIs, so you should have
a direct dependency on it. (check `mvn dependency:analyze`)

It took me a while to understand what you wrote and happenned here, but I think I got it right now.

p4 is optional and it should stay there IMHO. perforce functionality is absolutely custom and therefore optional for jira plugin for users using git (majority).
The JENKINS-64002 bug is however about basic Credential user/password saving to JIRA instance itself that bails out at the main manage configuration
screen.

So if I read you correct, you are saying that all the  org.jenkins-ci.plugin:*:compile dependencies that are in the "Undeclared used dependencies" output from dependency:analyze - should be added to direct dependencies?

And indeed, that's exactly what I would like to "detect with @JenkinsRule or during compilation phase" - but the root cause here was that the p4 maven included "credentials api" for compilation through optional p4 dependency but not introduced a direct plugin dependency in Jenkins plugin system.
 
So I think that the better solution is to actually exclude org.jenkins-ci.plugin:* from the optional dependencies instead - see https://github.com/jenkinsci/jira-plugin/pull/292/files
This way the plugin fails on compilation with no direct dependency declared and still optional dependency is ok.

Thanks a lot for pointing in the right direction!


In general, use `optional` dependencies only with extreme care; see
JENKINS-19508 for discussion.

BTW your plugin does not build in `master`, perhaps because #277
introduced a mistake that #290 caught, or similar.
 
Not sure what you mean, the plugin pipeline is green on master branch - https://github.com/jenkinsci/jira-plugin
 

Jesse Glick

unread,
Oct 23, 2020, 1:07:01 PM10/23/20
to Jenkins Dev
On Fri, Oct 23, 2020 at 1:00 PM Radosław Antoniuk
<radek.a...@gmail.com> wrote:
> you are saying that all the org.jenkins-ci.plugin:*:compile dependencies that are in the "Undeclared used dependencies" output from dependency:analyze - should be added to direct dependencies?

Yes, something like that. We do not currently try to enforce this
mechanically since the exceptions are tricky to characterize.

> exclude org.jenkins-ci.plugin:* from the optional dependencies instead - see https://github.com/jenkinsci/jira-plugin/pull/292/files

Fine if all of those excluded dependencies are added as direct
dependencies anyway. If they are not, then you might run into
`ClassNotFoundException`’s in tests, depending on what you are
testing.
Reply all
Reply to author
Forward
0 new messages