diff --git a/core/deployment/src/main/java/io/quarkus/deployment/builditem/nativeimage/ExcludeConfigBuildItem.java b/core/deployment/src/main/java/io/quarkus/deployment/builditem/nativeimage/ExcludeConfigBuildItem.java new file mode 100644 index 0000000000000..fc6e88f8116f8 --- /dev/null +++ b/core/deployment/src/main/java/io/quarkus/deployment/builditem/nativeimage/ExcludeConfigBuildItem.java @@ -0,0 +1,41 @@ +package io.quarkus.deployment.builditem.nativeimage; + +import io.quarkus.builder.item.MultiBuildItem; + +/** + * A build item that allows extension to configure the native-image compiler to effectively + * ignore certain configuration files in specific jars. + * + * The {@code jarFile} property specifies the name of the jar file or a regular expression that can be used to + * match multiple jar files. + * Matching jar files using regular expressions should be done as a last resort. + * + * The {@code resourceName} property specifies the name of the resource file or a regular expression that can be used to + * match multiple resource files. + * For the match to work, the resources need to be part of the matched jar file(s) (see {@code jarFile}). + * Matching resource files using regular expressions should be done as a last resort. + * + * See https://github.com/oracle/graal/pull/3179 for more details. + */ +public final class ExcludeConfigBuildItem extends MultiBuildItem { + + private final String jarFile; + private final String resourceName; + + public ExcludeConfigBuildItem(String jarFile, String resourceName) { + this.jarFile = jarFile; + this.resourceName = resourceName; + } + + public ExcludeConfigBuildItem(String jarFile) { + this(jarFile, "META-INF/native-image/native-image.properties"); + } + + public String getJarFile() { + return jarFile; + } + + public String getResourceName() { + return resourceName; + } +} diff --git a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java index 2210a067887cb..e1dba7ed6f7e9 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java @@ -26,6 +26,7 @@ import io.quarkus.bootstrap.model.AppDependency; import io.quarkus.bootstrap.util.IoUtils; import io.quarkus.deployment.annotations.BuildStep; +import io.quarkus.deployment.builditem.nativeimage.ExcludeConfigBuildItem; import io.quarkus.deployment.builditem.nativeimage.NativeImageSecurityProviderBuildItem; import io.quarkus.deployment.builditem.nativeimage.NativeImageSystemPropertyBuildItem; import io.quarkus.deployment.pkg.NativeConfig; @@ -81,7 +82,8 @@ ArtifactResultBuildItem nativeSourcesResult(NativeConfig nativeConfig, NativeImageSourceJarBuildItem nativeImageSourceJarBuildItem, OutputTargetBuildItem outputTargetBuildItem, PackageConfig packageConfig, - List nativeImageProperties) { + List nativeImageProperties, + List excludeConfigs) { Path outputDir; try { @@ -100,6 +102,7 @@ ArtifactResultBuildItem nativeSourcesResult(NativeConfig nativeConfig, .setNativeConfig(nativeConfig) .setOutputTargetBuildItem(outputTargetBuildItem) .setNativeImageProperties(nativeImageProperties) + .setExcludeConfigs(excludeConfigs) .setOutputDir(outputDir) .setRunnerJarName(runnerJar.getFileName().toString()) // the path to native-image is not known now, it is only known at the time the native-sources will be consumed @@ -130,6 +133,7 @@ public NativeImageBuildItem build(NativeConfig nativeConfig, NativeImageSourceJa PackageConfig packageConfig, CurateOutcomeBuildItem curateOutcomeBuildItem, List nativeImageProperties, + List excludeConfigs, List nativeImageSecurityProviders, Optional processInheritIODisabled) { if (nativeConfig.debug.enabled) { @@ -187,6 +191,7 @@ public NativeImageBuildItem build(NativeConfig nativeConfig, NativeImageSourceJa .setNativeConfig(nativeConfig) .setOutputTargetBuildItem(outputTargetBuildItem) .setNativeImageProperties(nativeImageProperties) + .setExcludeConfigs(excludeConfigs) .setNativeImageSecurityProviders(nativeImageSecurityProviders) .setOutputDir(outputDir) .setRunnerJarName(runnerJarName) @@ -477,6 +482,7 @@ static class Builder { private NativeConfig nativeConfig; private OutputTargetBuildItem outputTargetBuildItem; private List nativeImageProperties; + private List excludeConfigs; private List nativeImageSecurityProviders; private Path outputDir; private String runnerJarName; @@ -500,6 +506,11 @@ public Builder setNativeImageProperties(List return this; } + public Builder setExcludeConfigs(List excludeConfigs) { + this.excludeConfigs = excludeConfigs; + return this; + } + public Builder setNativeImageSecurityProviders( List nativeImageSecurityProviders) { this.nativeImageSecurityProviders = nativeImageSecurityProviders; @@ -700,6 +711,13 @@ public NativeImageInvokerInfo build() { .collect(Collectors.joining(",")); nativeImageArgs.add("-H:AdditionalSecurityProviders=" + additionalSecurityProviders); } + + // --exclude-config options + for (ExcludeConfigBuildItem excludeConfig : excludeConfigs) { + nativeImageArgs.add("--exclude-config"); + nativeImageArgs.add(excludeConfig.getJarFile()); + nativeImageArgs.add(excludeConfig.getResourceName()); + } } nativeImageArgs.add(nativeImageName);