Skip to content

Commit

Permalink
Merge branch '2.7.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
wilkinsona committed Mar 15, 2022
2 parents 0e07eb2 + b4cbcd7 commit 98678ed
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.gradle.api.attributes.LibraryElements;
import org.gradle.api.attributes.Usage;
import org.gradle.api.file.FileCollection;
import org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact;
import org.gradle.api.model.ObjectFactory;
import org.gradle.api.plugins.ApplicationPlugin;
import org.gradle.api.plugins.BasePlugin;
Expand Down Expand Up @@ -132,8 +131,7 @@ private void configureBootBuildImageTask(Project project, TaskProvider<BootJar>

@SuppressWarnings("deprecation")
private void configureArtifactPublication(TaskProvider<BootJar> bootJar) {
LazyPublishArtifact artifact = new LazyPublishArtifact(bootJar);
this.singlePublishedArtifact.addJarCandidate(artifact);
this.singlePublishedArtifact.addJarCandidate(bootJar);
}

private void configureBootRunTask(Project project) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,16 @@
package org.springframework.boot.gradle.plugin;

import org.gradle.api.Buildable;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.PublishArtifact;
import org.gradle.api.artifacts.PublishArtifactSet;
import org.gradle.api.artifacts.dsl.ArtifactHandler;
import org.gradle.api.tasks.TaskDependency;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.api.tasks.bundling.Jar;

import org.springframework.boot.gradle.tasks.bundling.BootJar;
import org.springframework.boot.gradle.tasks.bundling.BootWar;

/**
* A wrapper for a {@link PublishArtifactSet} that ensures that only a single artifact is
Expand All @@ -30,33 +37,35 @@
*/
final class SinglePublishedArtifact implements Buildable {

private final PublishArtifactSet artifacts;
private final Configuration configuration;

private final ArtifactHandler handler;

private PublishArtifact currentArtifact;

SinglePublishedArtifact(PublishArtifactSet artifacts) {
this.artifacts = artifacts;
SinglePublishedArtifact(Configuration configuration, ArtifactHandler handler) {
this.configuration = configuration;
this.handler = handler;
}

void addWarCandidate(PublishArtifact candidate) {
void addWarCandidate(TaskProvider<BootWar> candidate) {
add(candidate);
}

void addJarCandidate(PublishArtifact candidate) {
void addJarCandidate(TaskProvider<BootJar> candidate) {
if (this.currentArtifact == null) {
add(candidate);
}
}

private void add(PublishArtifact artifact) {
this.artifacts.remove(this.currentArtifact);
this.artifacts.add(artifact);
this.currentArtifact = artifact;
private void add(TaskProvider<? extends Jar> artifact) {
this.configuration.getArtifacts().remove(this.currentArtifact);
this.currentArtifact = this.handler.add(this.configuration.getName(), artifact);
}

@Override
public TaskDependency getBuildDependencies() {
return this.artifacts.getBuildDependencies();
return this.configuration.getArtifacts().getBuildDependencies();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ private Configuration createBootArchivesConfiguration(Project project) {
}

private void registerPluginActions(Project project, Configuration bootArchives) {
SinglePublishedArtifact singlePublishedArtifact = new SinglePublishedArtifact(bootArchives.getArtifacts());
SinglePublishedArtifact singlePublishedArtifact = new SinglePublishedArtifact(bootArchives,
project.getArtifacts());
List<PluginApplicationAction> actions = Arrays.asList(new JavaPluginAction(singlePublishedArtifact),
new WarPluginAction(singlePublishedArtifact), new DependencyManagementPluginAction(),
new ApplicationPluginAction(), new KotlinPluginAction());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.ConfigurationContainer;
import org.gradle.api.file.FileCollection;
import org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact;
import org.gradle.api.plugins.BasePlugin;
import org.gradle.api.plugins.WarPlugin;
import org.gradle.api.provider.Provider;
Expand Down Expand Up @@ -108,8 +107,7 @@ private void configureBootBuildImageTask(Project project, TaskProvider<BootWar>

@SuppressWarnings("deprecation")
private void configureArtifactPublication(TaskProvider<BootWar> bootWar) {
LazyPublishArtifact artifact = new LazyPublishArtifact(bootWar);
this.singlePublishedArtifact.addWarCandidate(artifact);
this.singlePublishedArtifact.addWarCandidate(bootWar);
}

}

0 comments on commit 98678ed

Please sign in to comment.