Add jar validation and fix multi-release jar

See gh-35768

Signed-off-by: Clayton Walker <clayton.m.walker@gmail.com>
This commit is contained in:
Brian Clozel
2025-11-07 15:20:27 +01:00
parent 21d3b2d179
commit 06ae7fb2b5
3 changed files with 45 additions and 1 deletions
@@ -27,6 +27,9 @@ import org.gradle.api.plugins.ExtensionContainer;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.tasks.TaskContainer;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.api.tasks.bundling.AbstractArchiveTask;
import org.gradle.jvm.tasks.Jar;
import org.gradle.jvm.toolchain.JavaToolchainService;
/**
@@ -57,5 +60,9 @@ public class MultiReleaseJarPlugin implements Plugin<Project> {
tasks,
dependencies,
objects);
TaskProvider<MultiReleaseJarValidateTask> validateJarTask = tasks.register("validateJar", MultiReleaseJarValidateTask.class, (task) -> {
task.getJar().set(tasks.named("jar", Jar.class).flatMap(AbstractArchiveTask::getArchiveFile));
});
tasks.named("check", task -> task.dependsOn(validateJarTask));
}
}
@@ -0,0 +1,37 @@
/*
* Copyright 2002-present the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.build.multirelease;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.tasks.CacheableTask;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.JavaExec;
import org.gradle.api.tasks.PathSensitive;
import org.gradle.api.tasks.PathSensitivity;
import java.util.List;
@CacheableTask
public abstract class MultiReleaseJarValidateTask extends JavaExec {
@InputFile
@PathSensitive(PathSensitivity.RELATIVE)
public abstract RegularFileProperty getJar();
public MultiReleaseJarValidateTask() {
getMainModule().set("jdk.jartool");
getArgumentProviders().add(() -> List.of("--validate", "--file", getJar().get().getAsFile().getAbsolutePath()));
}
}
@@ -30,7 +30,7 @@ import org.springframework.core.io.ResourceLoader;
* @author Brian Clozel
* @since 7.0
*/
public class ClassFileMetadataReaderFactory extends AbstractMetadataReaderFactory {
class ClassFileMetadataReaderFactory extends AbstractMetadataReaderFactory {
/**
* Create a new ClassFileMetadataReaderFactory for the default class loader.