Prevent eager creation of bootWar task
Previously, querying the artifact's extension in SinglePublishedArtifact would result in eager creation of the task that creates the artifact. Typically, this is the bootWar task. Instead of querying the extension, this commit reworks SinglePublishedArtifact and its callers to call separate methods for jar and war artifacts so that the extension check is no longer required. Tests have been added to ensure that running help does not trigger any unexpected task creation. The tests' assertions tolerate some variation in behavior that depend on the version of Gradle and whether the configuration cache is enabled. Closes gh-30211
This commit is contained in:
@@ -133,7 +133,7 @@ final class JavaPluginAction implements PluginApplicationAction {
|
||||
|
||||
private void configureArtifactPublication(TaskProvider<BootJar> bootJar) {
|
||||
LazyPublishArtifact artifact = new LazyPublishArtifact(bootJar);
|
||||
this.singlePublishedArtifact.addCandidate(artifact);
|
||||
this.singlePublishedArtifact.addJarCandidate(artifact);
|
||||
}
|
||||
|
||||
private void configureBootRunTask(Project project) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2020 the original author or authors.
|
||||
* Copyright 2012-2022 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.
|
||||
@@ -38,14 +38,22 @@ final class SinglePublishedArtifact implements Buildable {
|
||||
this.artifacts = artifacts;
|
||||
}
|
||||
|
||||
void addCandidate(PublishArtifact candidate) {
|
||||
if (this.currentArtifact == null || "war".equals(candidate.getExtension())) {
|
||||
this.artifacts.remove(this.currentArtifact);
|
||||
this.artifacts.add(candidate);
|
||||
this.currentArtifact = candidate;
|
||||
void addWarCandidate(PublishArtifact candidate) {
|
||||
add(candidate);
|
||||
}
|
||||
|
||||
void addJarCandidate(PublishArtifact candidate) {
|
||||
if (this.currentArtifact == null) {
|
||||
add(candidate);
|
||||
}
|
||||
}
|
||||
|
||||
private void add(PublishArtifact artifact) {
|
||||
this.artifacts.remove(this.currentArtifact);
|
||||
this.artifacts.add(artifact);
|
||||
this.currentArtifact = artifact;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskDependency getBuildDependencies() {
|
||||
return this.artifacts.getBuildDependencies();
|
||||
|
||||
@@ -108,7 +108,7 @@ class WarPluginAction implements PluginApplicationAction {
|
||||
|
||||
private void configureArtifactPublication(TaskProvider<BootWar> bootWar) {
|
||||
LazyPublishArtifact artifact = new LazyPublishArtifact(bootWar);
|
||||
this.singlePublishedArtifact.addCandidate(artifact);
|
||||
this.singlePublishedArtifact.addWarCandidate(artifact);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user