diff --git a/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy b/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy index d82302c84742e..60469622484e5 100644 --- a/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy +++ b/buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/PrecommitTasks.groovy @@ -87,6 +87,7 @@ class PrecommitTasks { dependsOn(buildResources) signatureFile = buildResources.copy("forbidden/third-party-audit.txt") javaHome = project.runtimeJavaHome + targetCompatibility = project.runtimeJavaVersion } return thirdPartyAuditTask } diff --git a/buildSrc/src/main/java/org/elasticsearch/gradle/precommit/ThirdPartyAuditTask.java b/buildSrc/src/main/java/org/elasticsearch/gradle/precommit/ThirdPartyAuditTask.java index d1939d5c65261..7e4766ada6541 100644 --- a/buildSrc/src/main/java/org/elasticsearch/gradle/precommit/ThirdPartyAuditTask.java +++ b/buildSrc/src/main/java/org/elasticsearch/gradle/precommit/ThirdPartyAuditTask.java @@ -23,6 +23,7 @@ import org.elasticsearch.test.NamingConventionsCheck; import org.gradle.api.DefaultTask; import org.gradle.api.GradleException; +import org.gradle.api.JavaVersion; import org.gradle.api.artifacts.Configuration; import org.gradle.api.file.FileCollection; import org.gradle.api.tasks.Input; @@ -66,6 +67,17 @@ public class ThirdPartyAuditTask extends DefaultTask { private String javaHome; + private JavaVersion targetCompatibility; + + @Input + public JavaVersion getTargetCompatibility() { + return targetCompatibility; + } + + public void setTargetCompatibility(JavaVersion targetCompatibility) { + this.targetCompatibility = targetCompatibility; + } + @InputFiles public Configuration getForbiddenAPIsConfiguration() { return getProject().getConfigurations().getByName("forbiddenApisCliJar"); @@ -157,10 +169,19 @@ public void runThirdPartyAudit() throws IOException { private void extractJars(FileCollection jars) { File jarExpandDir = getJarExpandDir(); + // We need to clean up to make sure old dependencies don't linger + getProject().delete(jarExpandDir); jars.forEach(jar -> getProject().copy(spec -> { spec.from(getProject().zipTree(jar)); spec.into(jarExpandDir); + // Exclude classes for multi release jars above target + for (int i = Integer.parseInt(targetCompatibility.getMajorVersion()) + 1; + i <= Integer.parseInt(JavaVersion.VERSION_HIGHER.getMajorVersion()); + i++ + ) { + spec.exclude("META-INF/versions/" + i + "/**"); + } }) ); } diff --git a/server/build.gradle b/server/build.gradle index 3fbe90aa29d2e..134b8aceebba5 100644 --- a/server/build.gradle +++ b/server/build.gradle @@ -314,21 +314,6 @@ thirdPartyAudit.excludes = [ 'com.google.common.geometry.S2LatLng', ] -if (project.runtimeJavaVersion <= JavaVersion.VERSION_1_8) { - thirdPartyAudit.excludes += [ - // Used by Log4J 2.11.1 - 'java.io.ObjectInputFilter', - 'java.io.ObjectInputFilter$Config', - 'java.io.ObjectInputFilter$FilterInfo', - 'java.io.ObjectInputFilter$Status', - // added in 9 - 'java.lang.ProcessHandle', - 'java.lang.StackWalker', - 'java.lang.StackWalker$Option', - 'java.lang.StackWalker$StackFrame' - ] -} - if (project.runtimeJavaVersion > JavaVersion.VERSION_1_8) { thirdPartyAudit.excludes += ['javax.xml.bind.DatatypeConverter'] } diff --git a/test/logger-usage/build.gradle b/test/logger-usage/build.gradle index 2da9065641436..6ab975fd42eba 100644 --- a/test/logger-usage/build.gradle +++ b/test/logger-usage/build.gradle @@ -42,23 +42,4 @@ thirdPartyAudit.excludes = [ 'org.osgi.framework.SynchronousBundleListener', 'org.osgi.framework.wiring.BundleWire', 'org.osgi.framework.wiring.BundleWiring' -] - -if (project.runtimeJavaVersion <= JavaVersion.VERSION_1_8) { - // Used by Log4J 2.11.1 - thirdPartyAudit.excludes += [ - 'java.io.ObjectInputFilter', - 'java.io.ObjectInputFilter$Config', - 'java.io.ObjectInputFilter$FilterInfo', - 'java.io.ObjectInputFilter$Status' - ] -} - -if (project.runtimeJavaVersion == JavaVersion.VERSION_1_8) { - thirdPartyAudit.excludes += [ - 'java.lang.ProcessHandle', - 'java.lang.StackWalker', - 'java.lang.StackWalker$Option', - 'java.lang.StackWalker$StackFrame' - ] -} \ No newline at end of file +] \ No newline at end of file diff --git a/x-pack/plugin/sql/sql-action/build.gradle b/x-pack/plugin/sql/sql-action/build.gradle index ee99c36b90627..9e53c36bbf600 100644 --- a/x-pack/plugin/sql/sql-action/build.gradle +++ b/x-pack/plugin/sql/sql-action/build.gradle @@ -138,23 +138,4 @@ thirdPartyAudit.excludes = [ 'org.zeromq.ZMQ$Context', 'org.zeromq.ZMQ$Socket', 'org.zeromq.ZMQ' -] - -if (project.runtimeJavaVersion <= JavaVersion.VERSION_1_8) { - // Used by Log4J 2.11.1 - thirdPartyAudit.excludes += [ - 'java.io.ObjectInputFilter', - 'java.io.ObjectInputFilter$Config', - 'java.io.ObjectInputFilter$FilterInfo', - 'java.io.ObjectInputFilter$Status' - ] -} - -if (project.runtimeJavaVersion == JavaVersion.VERSION_1_8) { - thirdPartyAudit.excludes += [ - 'java.lang.ProcessHandle', - 'java.lang.StackWalker', - 'java.lang.StackWalker$Option', - 'java.lang.StackWalker$StackFrame' - ] -} \ No newline at end of file +] \ No newline at end of file