Do not validate settings if publishing is disabled

This commit improves the Maven Plugin to only validate the publishing
settings if publishing is actually enabled.

Closes gh-29756
This commit is contained in:
Stéphane Nicoll
2024-07-29 15:36:57 +02:00
parent 9f1c4b71aa
commit 47465f6ed5
3 changed files with 53 additions and 21 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 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.
@@ -246,9 +246,10 @@ public abstract class BuildImageMojo extends AbstractPackagerMojo {
private void buildImage() throws MojoExecutionException {
Libraries libraries = getLibraries(Collections.emptySet());
try {
DockerConfiguration dockerConfiguration = (this.docker != null) ? this.docker.asDockerConfiguration()
: new Docker().asDockerConfiguration();
BuildRequest request = getBuildRequest(libraries);
DockerConfiguration dockerConfiguration = (this.docker != null)
? this.docker.asDockerConfiguration(request.isPublish())
: new Docker().asDockerConfiguration(request.isPublish());
Builder builder = new Builder(new MojoBuildLog(this::getLog), dockerConfiguration);
builder.build(request);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 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.
@@ -140,14 +140,15 @@ public class Docker {
* Returns this configuration as a {@link DockerConfiguration} instance. This method
* should only be called when the configuration is complete and will no longer be
* changed.
* @param publish whether the image should be published
* @return the Docker configuration
*/
DockerConfiguration asDockerConfiguration() {
DockerConfiguration asDockerConfiguration(boolean publish) {
DockerConfiguration dockerConfiguration = new DockerConfiguration();
dockerConfiguration = customizeHost(dockerConfiguration);
dockerConfiguration = dockerConfiguration.withBindHostToBuilder(this.bindHostToBuilder);
dockerConfiguration = customizeBuilderAuthentication(dockerConfiguration);
dockerConfiguration = customizePublishAuthentication(dockerConfiguration);
dockerConfiguration = customizePublishAuthentication(dockerConfiguration, publish);
return dockerConfiguration;
}
@@ -180,7 +181,11 @@ public class Docker {
"Invalid Docker builder registry configuration, either token or username/password must be provided");
}
private DockerConfiguration customizePublishAuthentication(DockerConfiguration dockerConfiguration) {
private DockerConfiguration customizePublishAuthentication(DockerConfiguration dockerConfiguration,
boolean publish) {
if (!publish) {
return dockerConfiguration;
}
if (this.publishRegistry == null || this.publishRegistry.isEmpty()) {
return dockerConfiguration.withEmptyPublishRegistryAuthentication();
}