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:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user