From 6d5108d271219b4f00f746889035213e2ebcb63c Mon Sep 17 00:00:00 2001 From: Alexis Tual Date: Tue, 25 Jun 2024 10:29:59 +0200 Subject: [PATCH] Update Jenkins min version and adapt build (#461) * Update Jenkins versions and adapt JDK requirement Latest Jenkins requires Java 17 or above. Recently added plugin dependencies (jackson) require Jenkins 2.401.3 Jenkins 2.401.3 requires Java 11 or above. Animal Sniffer is not needed with Java 11, replaced by compileJava `options.release = 11`. * Remove `autoInjectionSkippedWhenOldMavenPlugin` test as it requires maven-plugin 3.14 which won't install on the current Jenkins version * Try to kill Gradle daemons on Windows * Try again to kill Gradle daemons on Windows * Ignore CodeNarc warn --- acceptance-tests/build.gradle.kts | 11 ++++--- .../plugins/gradle/MavenInjectionTest.java | 23 -------------- build.gradle.kts | 31 +++++++++---------- settings.gradle.kts | 4 --- .../gradle/BaseGradleIntegrationTest.groovy | 19 ++++++++++++ .../gradle/BuildScanIntegrationTest.groovy | 21 ++++++++++++- .../gradle/GradlePluginIntegrationTest.groovy | 6 ++-- ...dScanInjectionGradleIntegrationTest.groovy | 2 ++ .../injection/InjectionConfigTest.groovy | 6 ++-- 9 files changed, 68 insertions(+), 55 deletions(-) diff --git a/acceptance-tests/build.gradle.kts b/acceptance-tests/build.gradle.kts index d43bc2b2..c4d56679 100644 --- a/acceptance-tests/build.gradle.kts +++ b/acceptance-tests/build.gradle.kts @@ -45,7 +45,7 @@ val currentJava = JavaVersion.current() val jenkinsVersions = listOf( JenkinsVersion.LATEST, JenkinsVersion.LATEST_LTS, - JenkinsVersion.V2_375 + JenkinsVersion.V2_401 ) jenkinsVersions @@ -113,17 +113,18 @@ data class JenkinsVersion(val version: String, val downloadUrl: URL, val javaVer private const val LATEST_VERSION = "latest" private const val LATEST_LTS_VERSION = "latest-lts" - private const val V2_388_VERSION = "2.388" + private const val V2_401_VERSION = "2.401.3" private const val MIRROR = "https://updates.jenkins.io" private val JENKINS_VERSION_PATTERN = "^\\d+([.]\\d+)*?\$".toRegex() private val JAVA_11 = JavaLanguageVersion.of(11) + private val JAVA_17 = JavaLanguageVersion.of(17) - val LATEST = of(LATEST_VERSION) + val LATEST = of(LATEST_VERSION, JAVA_17) val LATEST_LTS = of(LATEST_LTS_VERSION) - val V2_375 = of(V2_388_VERSION) + val V2_401 = of(V2_401_VERSION) private fun of(version: String, javaVersion: JavaLanguageVersion = JAVA_11): JenkinsVersion { val downloadUrl = @@ -145,7 +146,7 @@ data class JenkinsVersion(val version: String, val downloadUrl: URL, val javaVer } val isDefault: Boolean - get() = version == V2_388_VERSION + get() = version == V2_401_VERSION val label: String get() = if (isJenkinsVersion(version)) { diff --git a/acceptance-tests/src/test/java/hudson/plugins/gradle/MavenInjectionTest.java b/acceptance-tests/src/test/java/hudson/plugins/gradle/MavenInjectionTest.java index cf93bc02..716653a4 100644 --- a/acceptance-tests/src/test/java/hudson/plugins/gradle/MavenInjectionTest.java +++ b/acceptance-tests/src/test/java/hudson/plugins/gradle/MavenInjectionTest.java @@ -1,7 +1,6 @@ package hudson.plugins.gradle; import com.google.common.collect.ImmutableMap; -import hudson.plugin.gradle.ath.updatecenter.WithVersionOverrides; import org.apache.commons.text.StringSubstitutor; import org.jenkinsci.test.acceptance.junit.WithOS; import org.jenkinsci.test.acceptance.junit.WithPlugins; @@ -54,28 +53,6 @@ public void mavenJobSendsBuildScan() { assertBuildScanPublished(build); } - @Test - @WithVersionOverrides("maven-plugin=3.14") - @WithPlugins("maven-plugin") - @Ignore("https://github.com/gradle/dv/issues/35892") - public void autoInjectionSkippedWhenOldMavenPlugin() { - // given - MavenModuleSet job = jenkins.jobs.create(MavenModuleSet.class); - - job.configure(); - job.copyDir(resource("/simple_maven_project")); - job.goals.set("clean compile"); - - job.save(); - - // when - Build build = job.startBuild(); - - // then - build.shouldSucceed(); - assertBuildScanNotPublished(build); - } - @Test public void freestyleJobSendsBuildScan() { // given diff --git a/build.gradle.kts b/build.gradle.kts index 11359ae4..ce11a640 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,6 @@ import java.util.zip.ZipFile plugins { id("org.jenkins-ci.jpi") version "0.50.0" - id("ru.vyarus.animalsniffer") version "1.7.1" id("com.github.spotbugs") version "6.0.15" id("codenarc") id("buildlogic.reproducible-archives") @@ -17,9 +16,9 @@ plugins { group = "org.jenkins-ci.plugins" description = "This plugin adds Gradle support to Jenkins" -val coreBaseVersion = "2.303" +val coreBaseVersion = "2.401" val corePatchVersion = "3" -val coreBomVersion = "1500.ve4d05cd32975" +val coreBomVersion = "2745.vc7b_fe4c876fa_" val gradleExt = (gradle as ExtensionAware).extra @@ -71,7 +70,7 @@ jenkinsPlugin { java { toolchain { - languageVersion.set(JavaLanguageVersion.of(8)) + languageVersion.set(JavaLanguageVersion.of(11)) } registerFeature("optionalPlugin") { @@ -79,6 +78,10 @@ java { } } +tasks.compileJava { + options.release = 11 +} + // see https://github.com/jenkinsci/gradle-jpi-plugin#customizing-further tasks.server.configure { execSpec { @@ -102,8 +105,10 @@ dependencies { implementation("org.jenkins-ci.plugins.workflow:workflow-step-api") implementation("io.jenkins.plugins:okhttp-api") - "optionalPluginImplementation"("org.jenkins-ci.main:maven-plugin:3.14") { + "optionalPluginImplementation"("org.jenkins-ci.main:maven-plugin:3.23") { because("Lowest version that works with our dependencies") + // conflicts with Jenkins bom bringing Guice 6.0.0 + exclude(group = "com.google.inject", module = "guice") } // Higher versions fail in our tests with ClassNotFoundException during SCM initialization unless Jenkins is updated @@ -120,9 +125,7 @@ dependencies { add(includedLibs.name, "com.gradle:common-custom-user-data-maven-extension:${commonCustomUserDataMavenExtensionVersion}") add(includedLibs.name, project(path = ":configuration-maven-extension", configuration = "mvnExtension")) - signature("org.codehaus.mojo.signature:java18:1.0@signature") - - testImplementation("org.jenkins-ci.main:jenkins-test-harness") + testImplementation("org.jenkins-ci.main:jenkins-test-harness:2225.v04fa_3929c9b_5") testImplementation("org.jenkins-ci.main:jenkins-test-harness-tools:2.2") testImplementation("io.jenkins:configuration-as-code:1.4") testImplementation("org.jenkins-ci.plugins:timestamper") @@ -175,13 +178,6 @@ tasks.spotbugsTest { val main: SourceSet by sourceSets.getting -animalsniffer { - toolVersion = "1.18" - sourceSets = listOf(main) - // We need to exclude this dependency from animalsniffer since it contains an invalid class - excludeJars = listOf("icu4j-*") -} - val test: SourceSet by sourceSets.getting codenarc { @@ -193,7 +189,10 @@ tasks.test { systemProperties( mapOf( "hudson.model.DownloadService.noSignatureCheck" to true, - "jenkins.test.timeout" to 300 // override default timeout + "jenkins.test.timeout" to 300, // override default timeout + "jdk8.home" to javaToolchains.compilerFor { + languageVersion = JavaLanguageVersion.of(8) + }.get().metadata.installationPath.toString() ) ) ignoreFailures = ciJenkinsBuild diff --git a/settings.gradle.kts b/settings.gradle.kts index 25b83e2e..1b858298 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -11,10 +11,6 @@ include("configuration-maven-extension") rootProject.name = "gradle-plugin" -if (!JavaVersion.current().isJava11) { - throw GradleException("Build requires Java 11") -} - val gradleExt = (gradle as ExtensionAware).extra val ciJenkinsBuild by gradleExt { System.getenv("JENKINS_URL") != null } diff --git a/src/test/groovy/hudson/plugins/gradle/BaseGradleIntegrationTest.groovy b/src/test/groovy/hudson/plugins/gradle/BaseGradleIntegrationTest.groovy index 82a9a4d3..eb237a19 100644 --- a/src/test/groovy/hudson/plugins/gradle/BaseGradleIntegrationTest.groovy +++ b/src/test/groovy/hudson/plugins/gradle/BaseGradleIntegrationTest.groovy @@ -3,6 +3,7 @@ package hudson.plugins.gradle import com.cloudbees.plugins.credentials.CredentialsProvider import com.cloudbees.plugins.credentials.CredentialsScope import com.cloudbees.plugins.credentials.domains.Domain +import hudson.Functions import hudson.slaves.DumbSlave import hudson.util.Secret import org.jenkinsci.plugins.plaincredentials.StringCredentials @@ -10,6 +11,8 @@ import org.jenkinsci.plugins.plaincredentials.impl.StringCredentialsImpl import org.junit.Rule import org.junit.rules.RuleChain +import java.util.concurrent.TimeUnit + /** * Base class for tests that need a Jenkins instance and Gradle tool. */ @@ -64,4 +67,20 @@ abstract class BaseGradleIntegrationTest extends AbstractIntegrationTest { CredentialsProvider.lookupStores(j.jenkins).iterator().next().addCredentials(Domain.global(), creds) } + @SuppressWarnings("CatchException") + def cleanup() { + if(Functions.isWindows()) { + try { + println 'Killing Gradle processes' + def proc = '''WMIC PROCESS where "Name like 'java%%' AND CommandLine like '%%GradleDaemon%%'" Call Terminate"'''.execute() + proc.waitFor(30, TimeUnit.SECONDS) + println "output: ${proc.text}" + println "code: ${proc.exitValue()}" + } catch (Exception e) { + System.err.println('Failed killing Gradle daemons') + e.printStackTrace() + } + } + } + } diff --git a/src/test/groovy/hudson/plugins/gradle/BuildScanIntegrationTest.groovy b/src/test/groovy/hudson/plugins/gradle/BuildScanIntegrationTest.groovy index 701d8c41..d186ddf5 100644 --- a/src/test/groovy/hudson/plugins/gradle/BuildScanIntegrationTest.groovy +++ b/src/test/groovy/hudson/plugins/gradle/BuildScanIntegrationTest.groovy @@ -1,6 +1,7 @@ package hudson.plugins.gradle import hudson.model.FreeStyleProject +import hudson.model.JDK import hudson.plugins.gradle.injection.MavenSnippets import hudson.plugins.timestamper.TimestamperBuildWrapper import hudson.tasks.BatchFile @@ -13,16 +14,23 @@ import org.jvnet.hudson.test.CreateFileBuilder import org.jvnet.hudson.test.ExtractResourceSCM import org.jvnet.hudson.test.JenkinsRule import org.jvnet.hudson.test.ToolInstallations +import spock.lang.Requires import spock.lang.Unroll +import java.nio.file.Files +import java.nio.file.Paths + @Unroll @SuppressWarnings("GStringExpressionWithinString") class BuildScanIntegrationTest extends BaseGradleIntegrationTest { + private static final String JDK8_SYS_PROP = 'jdk8.home' + @Requires(value = { hasJdk8() }, reason = "Gradle 3 and 4 require Java 8") def 'build scans for plugin version #buildScanVersion is discovered'() { given: gradleInstallationRule.gradleVersion = gradleVersion gradleInstallationRule.addInstallation() + setJdk8() FreeStyleProject p = j.createFreeStyleProject() p.buildersList.add(buildScriptBuilder(buildScanVersion)) p.buildersList.add(new Gradle(tasks: 'hello', gradleName: gradleVersion, switches: "${args} --no-daemon")) @@ -251,15 +259,16 @@ stage('Final') { new URL(action.scanUrls.get(0)) } + @Requires(value = { hasJdk8() }, reason = "Gradle 3 and 4 require Java 8") def 'build scan action is exposed via rest API'() { given: gradleInstallationRule.gradleVersion = '3.4' gradleInstallationRule.addInstallation() + setJdk8() FreeStyleProject p = j.createFreeStyleProject() p.buildersList.add(buildScriptBuilder('1.8')) p.buildersList.add(new Gradle(tasks: 'hello', gradleName: '3.4', switches: '-Dscan --no-daemon')) - when: def build = j.buildAndAssertSuccess(p) @@ -305,4 +314,14 @@ tasks.register("hello") { doLast { println("Hello") } }''') private static CreateFileBuilder settingsScriptBuilder(String gePluginVersion) { return new CreateFileBuilder('settings.gradle', "plugins { id 'com.gradle.enterprise' version '${gePluginVersion}' }") } + + private setJdk8() { + j.jenkins.setJDKs(Collections.singleton(new JDK('JDK8', System.getProperty(JDK8_SYS_PROP)))) + } + + private static hasJdk8() { + def jdk8SysProp = System.getProperty(JDK8_SYS_PROP) + return jdk8SysProp && Files.exists(Paths.get(jdk8SysProp)) + } + } diff --git a/src/test/groovy/hudson/plugins/gradle/GradlePluginIntegrationTest.groovy b/src/test/groovy/hudson/plugins/gradle/GradlePluginIntegrationTest.groovy index 09926079..abb61463 100644 --- a/src/test/groovy/hudson/plugins/gradle/GradlePluginIntegrationTest.groovy +++ b/src/test/groovy/hudson/plugins/gradle/GradlePluginIntegrationTest.groovy @@ -24,9 +24,6 @@ package hudson.plugins.gradle -import com.gargoylesoftware.htmlunit.html.HtmlButton -import com.gargoylesoftware.htmlunit.html.HtmlForm -import com.gargoylesoftware.htmlunit.html.HtmlPage import com.google.common.base.Joiner import hudson.EnvVars import hudson.model.FreeStyleBuild @@ -34,6 +31,9 @@ import hudson.model.FreeStyleProject import hudson.model.Result import hudson.tools.InstallSourceProperty import hudson.util.VersionNumber +import org.htmlunit.html.HtmlButton +import org.htmlunit.html.HtmlForm +import org.htmlunit.html.HtmlPage import org.jvnet.hudson.test.CreateFileBuilder import org.jvnet.hudson.test.JenkinsRule.WebClient import spock.lang.Unroll diff --git a/src/test/groovy/hudson/plugins/gradle/injection/BuildScanInjectionGradleIntegrationTest.groovy b/src/test/groovy/hudson/plugins/gradle/injection/BuildScanInjectionGradleIntegrationTest.groovy index a0d38817..091e1166 100644 --- a/src/test/groovy/hudson/plugins/gradle/injection/BuildScanInjectionGradleIntegrationTest.groovy +++ b/src/test/groovy/hudson/plugins/gradle/injection/BuildScanInjectionGradleIntegrationTest.groovy @@ -363,6 +363,7 @@ class BuildScanInjectionGradleIntegrationTest extends BaseGradleIntegrationTest sh "'\${gradleHome}/bin/gradle' help --no-daemon --console=plain" } else { bat(/"\${gradleHome}\\bin\\gradle.bat" help --no-daemon --console=plain/) + bat(/"\${gradleHome}\\bin\\gradle.bat" --stop/) } } } @@ -859,6 +860,7 @@ class BuildScanInjectionGradleIntegrationTest extends BaseGradleIntegrationTest sh "'\${gradleHome}/bin/gradle' help --no-daemon --console=plain" } else { bat(/"\${gradleHome}\\bin\\gradle.bat" help --no-daemon --console=plain/) + bat(/"\${gradleHome}\\bin\\gradle.bat" --stop/) } } } diff --git a/src/test/groovy/hudson/plugins/gradle/injection/InjectionConfigTest.groovy b/src/test/groovy/hudson/plugins/gradle/injection/InjectionConfigTest.groovy index cd375d5e..82a6b7c0 100644 --- a/src/test/groovy/hudson/plugins/gradle/injection/InjectionConfigTest.groovy +++ b/src/test/groovy/hudson/plugins/gradle/injection/InjectionConfigTest.groovy @@ -1,11 +1,11 @@ package hudson.plugins.gradle.injection -import com.gargoylesoftware.htmlunit.html.HtmlButton -import com.gargoylesoftware.htmlunit.html.HtmlForm import hudson.plugins.gradle.BaseJenkinsIntegrationTest import hudson.slaves.EnvironmentVariablesNodeProperty import hudson.util.FormValidation import hudson.util.XStream2 +import org.htmlunit.html.HtmlButton +import org.htmlunit.html.HtmlForm import spock.lang.Shared import spock.lang.Subject import spock.lang.Unroll @@ -311,7 +311,7 @@ class InjectionConfigTest extends BaseJenkinsIntegrationTest { } private static HtmlButton getAddButton(HtmlForm form, String label) { - def xpath = "//div[contains(@class, 'setting-name') and text() = '$label']/following-sibling::div[contains(@class, 'setting-main')]//span[contains(@class, 'repeatable-add')]//button[text() = 'Add']" + def xpath = "//div[text() = '$label']/following-sibling::div[contains(@class, 'setting-main')]//span[contains(@class, 'repeatable-add')]//button[text() = 'Add']" return form.getFirstByXPath(xpath) } }