jenkinsci / gradle-jpi-plugin

Build Jenkins Plugins with Gradle
79 stars 50 forks source link

Add `useJenkinsRule` option for `Test` tasks #188

Open sghill opened 3 years ago

sghill commented 3 years ago

The changes in 0.43.0 included removing the jenkins-war from the classpath and defining system properties to define where the war is and where it would be unpacked to. This is a nice step forward because it ensures that multiple tasks are not writing to the same output directory and no longer requires the war and all its dependencies to be on the classpath.

However plugins like the jira-trigger-plugin have defined additional test tasks that also need to use the Jenkins rule. That isn't very straightforward today:

def integTestDir = project.layout.buildDir.dir('jpi-plugin/integrationTest')
def jpiTest = new org.jenkinsci.gradle.plugins.testing.JpiTestingPlugin.Companion()

task integrationTest(type: Test) { Test t ->
    jpiTest.useJenkinsRule(t, integTestDir)
    t.testClassesDirs = sourceSets.integrationTest.output
    t.classpath = sourceSets.integrationTest.runtimeClasspath
    t.mustRunAfter test
}

Instead of this, it would be much nicer to infer the directory and not have to instantiate another class.