As a java unit test will need jar files, it is then needed to load them nd to declare them within the pom.xml file or build.gradle file
testCompile("org.jenkins-ci.main:jenkins-test-harness:${jenkinsTestHarness}")
testCompile("org.jenkins-ci.main:jenkins-war:${jenkinsCore}")
testCompile("org.jenkins-ci.plugins:script-security:${jenkinsTestSecurityScript}@jar")
// Add the jar file as the testPlugins will install the hpi/jpi files and not the jar needed by the junit test
testCompile 'org.jenkins-ci.tools:git-parameter:0.9.13@jar'
testCompile 'org.jenkins-ci.plugins:structs:1.20@jar'
testCompile 'org.jenkins-ci.plugins:git:3.10.0@jar'
testCompile 'org.jenkins-ci.plugins:git-client:3.5.1@jar'
testCompile 'org.jenkins-ci.plugins:credentials:2.3.9@jar'
testCompile 'org.jenkins-ci.plugins:scm-api:2.6.4@jar'
testCompile 'org.jenkins-ci.plugins:matrix-project:1.18@jar'
testCompile 'org.jenkins-ci.plugins:global-variable-string-parameter:1.2@jar'
testCompile 'org.jenkins-ci.plugins:junit:1.47@jar'
testCompile 'org.jenkins-ci.plugins:workflow-remote-loader:1.5@jar'
testCompile 'org.jenkins-ci.plugins.workflow:workflow-aggregator:2.6@jar'
testCompile 'org.jenkins-ci.plugins.workflow:workflow-api:2.40@jar'
testCompile 'org.jenkins-ci.plugins.workflow:workflow-basic-steps:2.18@jar'
testCompile 'org.jenkins-ci.plugins.workflow:workflow-scm-step:2.11@jar'
testCompile 'org.jenkins-ci.plugins.workflow:workflow-cps:2.80@jar'
testCompile 'org.jenkins-ci.plugins.workflow:workflow-durable-task-step:2.35@jar'
testCompile 'org.jenkins-ci.plugins.workflow:workflow-job:2.38@jar'
testCompile 'org.jenkins-ci.plugins.workflow:workflow-multibranch:2.20@jar'
testCompile 'org.jenkins-ci.plugins.workflow:workflow-step-api:2.23@jar'
testCompile 'org.jenkins-ci.plugins.workflow:workflow-support:3.3@jar'
testCompile 'org.jenkins-ci.plugins:matrix-auth:2.6.2@jar'
testCompile 'org.eclipse.jgit:org.eclipse.jgit:5.10.0.202012080955-r'
// Plugins to install in test jenkins instance running locally
testPlugins 'org.jenkins-ci.main:maven-plugin:3.8'
testPlugins 'org.jenkins-ci.plugins:cloudbees-folder:5.14'
testPlugins 'org.jenkins-ci.plugins:credentials:2.3.9'
testPlugins 'org.jenkins-ci.plugins:structs:1.20'
testPlugins 'org.jenkins-ci.plugins:global-variable-string-parameter:1.2'
testPlugins 'org.jenkins-ci.tools:git-parameter:0.9.13'
testPlugins 'org.jenkins-ci.plugins:git:3.10.0'
testPlugins 'org.jenkins-ci.plugins:git-client:3.5.1'
testPlugins 'org.jenkins-ci.plugins:scm-api:2.6.4'
testPlugins 'org.jenkins-ci.plugins:matrix-project:1.18'
testPlugins 'org.jenkins-ci.plugins:workflow-remote-loader:1.5'
testPlugins 'org.jenkins-ci.plugins.workflow:workflow-aggregator:2.6'
testPlugins 'org.jenkins-ci.plugins.workflow:workflow-api:2.40'
testPlugins 'org.jenkins-ci.plugins.workflow:workflow-basic-steps:2.18'
testPlugins 'org.jenkins-ci.plugins.workflow:workflow-scm-step:2.11'
testPlugins 'org.jenkins-ci.plugins.workflow:workflow-cps:2.80'
testPlugins 'org.jenkins-ci.plugins.workflow:workflow-durable-task-step:2.35'
testPlugins 'org.jenkins-ci.plugins.workflow:workflow-job:2.38'
testPlugins 'org.jenkins-ci.plugins.workflow:workflow-multibranch:2.20'
testPlugins 'org.jenkins-ci.plugins.workflow:workflow-step-api:2.23'
testPlugins 'org.jenkins-ci.plugins.workflow:workflow-support:3.3'
testPlugins 'org.jenkins-ci.plugins:matrix-auth:2.6.2'
testPlugins 'org.jenkins-ci.plugins:junit:1.47'
testPlugins 'org.jenkins-ci.plugins:matrix-project:1.18'
As you can imagine, this process is long,tedious, will change when we upgrade to another jenkins server (as the list of the default plugins will be updated).
Is there a script, tool able to grab from jenkins the plugins list and next to create the corresponding plugins to be imported for Jenkinsrule unit test and GAVs dependencies (pom.xml or build.gradle) ?