From b1908ca8178cc65d14f6baba60dbb33f2efde43b Mon Sep 17 00:00:00 2001 From: Rahul Somasunderam Date: Wed, 8 Jan 2025 14:32:55 -0800 Subject: [PATCH] feat: Support Jenkins >= 2.475 Jenkins 2.475 and Jenkins LTS 2.479.1 introduce a change to the Java Servlet API version and the servlet container support policy. This takes it from JEE8 to JEE9. This changes the coordinates of servlet-api to jakarta. This gradle plugin can be built with JDK 11 but not with JDK 17 which would be required for adding the extra test to `JenkinsVersionIntegrationSpec`. Related: JENKINS-73278 --- .../gradle/plugins/jpi/internal/DependencyLookup.java | 10 +++++++--- .../plugins/jpi/JenkinsVersionIntegrationSpec.groovy | 6 ++++++ .../plugins/jpi/internal/DependencyLookupSpec.groovy | 3 +++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/jenkinsci/gradle/plugins/jpi/internal/DependencyLookup.java b/src/main/java/org/jenkinsci/gradle/plugins/jpi/internal/DependencyLookup.java index 68159696..e889da8a 100644 --- a/src/main/java/org/jenkinsci/gradle/plugins/jpi/internal/DependencyLookup.java +++ b/src/main/java/org/jenkinsci/gradle/plugins/jpi/internal/DependencyLookup.java @@ -73,9 +73,13 @@ private static DependencyFactory findbugsFor(VersionNumber version, boolean befo } private static DependencyFactory servletFor(VersionNumber version) { - boolean isBefore2 = version.isOlderThan(new VersionNumber("2.0")); - String notation = isBefore2 ? "javax.servlet:servlet-api:2.4" : "javax.servlet:javax.servlet-api:3.1.0"; - return new MavenDependency(notation); + if (version.isOlderThan(new VersionNumber("2.0"))) { + return new MavenDependency("javax.servlet:servlet-api:2.4"); + } else if (version.isOlderThan(new VersionNumber("2.475"))) { + return new MavenDependency("javax.servlet:javax.servlet-api:3.1.0"); + } else { + return new MavenDependency("jakarta.servlet:jakarta.servlet-api:5.0.0"); + } } private static DependencyFactory testHarnessFor(VersionNumber version) { diff --git a/src/test/groovy/org/jenkinsci/gradle/plugins/jpi/JenkinsVersionIntegrationSpec.groovy b/src/test/groovy/org/jenkinsci/gradle/plugins/jpi/JenkinsVersionIntegrationSpec.groovy index 855348d7..2728fd38 100644 --- a/src/test/groovy/org/jenkinsci/gradle/plugins/jpi/JenkinsVersionIntegrationSpec.groovy +++ b/src/test/groovy/org/jenkinsci/gradle/plugins/jpi/JenkinsVersionIntegrationSpec.groovy @@ -140,6 +140,7 @@ class JenkinsVersionIntegrationSpec extends IntegrationSpec { 'findbugs:annotations:1.0.0' : NOWHERE, 'javax.servlet:servlet-api:2.4' : NOWHERE, 'javax.servlet:javax.servlet-api:3.1.0' : COMPILE_ONLY, + 'jakarta.servlet:jakarta.servlet-api:5.0.0' : NOWHERE, 'org.jenkins-ci.main:jenkins-test-harness:2112.ve584e0edc63b_': TEST_IMPLEMENTATION_ONLY, 'org.jenkins-ci.main:ui-samples-plugin:2.0' : NOWHERE, 'junit:junit-dep:4.10' : NOWHERE, @@ -150,6 +151,7 @@ class JenkinsVersionIntegrationSpec extends IntegrationSpec { 'findbugs:annotations:1.0.0' : NOWHERE, 'javax.servlet:servlet-api:2.4' : NOWHERE, 'javax.servlet:javax.servlet-api:3.1.0' : COMPILE_ONLY, + 'jakarta.servlet:jakarta.servlet-api:5.0.0' : NOWHERE, 'org.jenkins-ci.main:jenkins-test-harness:2112.ve584e0edc63b_': TEST_IMPLEMENTATION_ONLY, 'org.jenkins-ci.main:ui-samples-plugin:2.0' : NOWHERE, 'junit:junit-dep:4.10' : NOWHERE, @@ -190,6 +192,7 @@ class JenkinsVersionIntegrationSpec extends IntegrationSpec { 'findbugs:annotations:1.0.0' : NOWHERE, 'javax.servlet:servlet-api:2.4' : COMPILE_ONLY, 'javax.servlet:javax.servlet-api:3.1.0' : NOWHERE, + 'jakarta.servlet:jakarta.servlet-api:5.0.0' : NOWHERE, 'org.jenkins-ci.main:jenkins-test-harness:2.0': TEST_IMPLEMENTATION_ONLY, 'org.jenkins-ci.main:ui-samples-plugin:2.0' : NOWHERE, 'junit:junit-dep:4.10' : NOWHERE, @@ -200,6 +203,7 @@ class JenkinsVersionIntegrationSpec extends IntegrationSpec { 'findbugs:annotations:1.0.0' : NOWHERE, 'javax.servlet:servlet-api:2.4' : COMPILE_ONLY, 'javax.servlet:javax.servlet-api:3.1.0' : NOWHERE, + 'jakarta.servlet:jakarta.servlet-api:5.0.0' : NOWHERE, 'org.jenkins-ci.main:jenkins-test-harness:2.0': TEST_IMPLEMENTATION_ONLY, 'org.jenkins-ci.main:ui-samples-plugin:2.0' : NOWHERE, 'junit:junit-dep:4.10' : NOWHERE, @@ -210,6 +214,7 @@ class JenkinsVersionIntegrationSpec extends IntegrationSpec { 'findbugs:annotations:1.0.0' : NOWHERE, 'javax.servlet:servlet-api:2.4' : COMPILE_ONLY, 'javax.servlet:javax.servlet-api:3.1.0' : NOWHERE, + 'jakarta.servlet:jakarta.servlet-api:5.0.0' : NOWHERE, 'org.jenkins-ci.main:jenkins-test-harness:1.644': TEST_IMPLEMENTATION_ONLY, 'org.jenkins-ci.main:ui-samples-plugin:2.0' : NOWHERE, 'junit:junit-dep:4.10' : NOWHERE, @@ -220,6 +225,7 @@ class JenkinsVersionIntegrationSpec extends IntegrationSpec { 'findbugs:annotations:1.0.0' : NOWHERE, 'javax.servlet:servlet-api:2.4' : COMPILE_ONLY, 'javax.servlet:javax.servlet-api:3.1.0' : NOWHERE, + 'jakarta.servlet:jakarta.servlet-api:5.0.0' : NOWHERE, 'org.jenkins-ci.main:jenkins-test-harness:1.618': TEST_IMPLEMENTATION_ONLY, 'org.jenkins-ci.main:ui-samples-plugin:2.0' : NOWHERE, 'junit:junit-dep:4.10' : NOWHERE, diff --git a/src/test/groovy/org/jenkinsci/gradle/plugins/jpi/internal/DependencyLookupSpec.groovy b/src/test/groovy/org/jenkinsci/gradle/plugins/jpi/internal/DependencyLookupSpec.groovy index ee59087e..ce9fac90 100644 --- a/src/test/groovy/org/jenkinsci/gradle/plugins/jpi/internal/DependencyLookupSpec.groovy +++ b/src/test/groovy/org/jenkinsci/gradle/plugins/jpi/internal/DependencyLookupSpec.groovy @@ -6,6 +6,7 @@ import spock.lang.Unroll class DependencyLookupSpec extends Specification { private static final MavenDependency JCIP_ANNOTATIONS = new MavenDependency('net.jcip:jcip-annotations:1.0') + private static final MavenDependency SERVLET_5_0 = new MavenDependency('jakarta.servlet:jakarta.servlet-api:5.0.0') private static final MavenDependency SERVLET_3_1 = new MavenDependency('javax.servlet:javax.servlet-api:3.1.0') private static final MavenDependency SERVLET_2_4 = new MavenDependency('javax.servlet:servlet-api:2.4') private static final MavenDependency GOOGLE_FINDBUGS = new MavenDependency('com.google.code.findbugs:annotations:3.0.0') @@ -28,6 +29,8 @@ class DependencyLookupSpec extends Specification { '2.222.3' | [jenkinsBom('2.222.3'), jenkinsCore('2.222.3'), SERVLET_3_1] as Set '2.361.2-rc32710.c1a_5e8c179f6' | [jenkinsBom('2.361.2-rc32710.c1a_5e8c179f6'), jenkinsCore('2.361.2-rc32710.c1a_5e8c179f6'), SERVLET_3_1] as Set '2.369-rc32854.076293e36922' | [jenkinsBom('2.369-rc32854.076293e36922'), jenkinsCore('2.369-rc32854.076293e36922'), SERVLET_3_1] as Set + '2.475' | [jenkinsBom('2.475'), jenkinsCore('2.475'), SERVLET_5_0] as Set + '2.479.2' | [jenkinsBom('2.479.2'), jenkinsCore('2.479.2'), SERVLET_5_0] as Set } @Unroll