Skip to content

Commit f32895b

Browse files
committed
Merge pull request #30209 from octylFractal
* gh-30209: Refactor code to avoid using internal LazyPublishArtifact Closes gh-30209
2 parents f11ddb4 + 264a688 commit f32895b

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/JavaPluginAction.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.gradle.api.attributes.LibraryElements;
3333
import org.gradle.api.attributes.Usage;
3434
import org.gradle.api.file.FileCollection;
35-
import org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact;
3635
import org.gradle.api.model.ObjectFactory;
3736
import org.gradle.api.plugins.ApplicationPlugin;
3837
import org.gradle.api.plugins.BasePlugin;
@@ -132,8 +131,7 @@ private void configureBootBuildImageTask(Project project, TaskProvider<BootJar>
132131
}
133132

134133
private void configureArtifactPublication(TaskProvider<BootJar> bootJar) {
135-
LazyPublishArtifact artifact = new LazyPublishArtifact(bootJar);
136-
this.singlePublishedArtifact.addJarCandidate(artifact);
134+
this.singlePublishedArtifact.addJarCandidate(bootJar);
137135
}
138136

139137
private void configureBootRunTask(Project project) {

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/SinglePublishedArtifact.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,16 @@
1717
package org.springframework.boot.gradle.plugin;
1818

1919
import org.gradle.api.Buildable;
20+
import org.gradle.api.artifacts.Configuration;
2021
import org.gradle.api.artifacts.PublishArtifact;
2122
import org.gradle.api.artifacts.PublishArtifactSet;
23+
import org.gradle.api.artifacts.dsl.ArtifactHandler;
2224
import org.gradle.api.tasks.TaskDependency;
25+
import org.gradle.api.tasks.TaskProvider;
26+
import org.gradle.api.tasks.bundling.Jar;
27+
28+
import org.springframework.boot.gradle.tasks.bundling.BootJar;
29+
import org.springframework.boot.gradle.tasks.bundling.BootWar;
2330

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

33-
private final PublishArtifactSet artifacts;
40+
private final Configuration configuration;
41+
42+
private final ArtifactHandler handler;
3443

3544
private PublishArtifact currentArtifact;
3645

37-
SinglePublishedArtifact(PublishArtifactSet artifacts) {
38-
this.artifacts = artifacts;
46+
SinglePublishedArtifact(Configuration configuration, ArtifactHandler handler) {
47+
this.configuration = configuration;
48+
this.handler = handler;
3949
}
4050

41-
void addWarCandidate(PublishArtifact candidate) {
51+
void addWarCandidate(TaskProvider<BootWar> candidate) {
4252
add(candidate);
4353
}
4454

45-
void addJarCandidate(PublishArtifact candidate) {
55+
void addJarCandidate(TaskProvider<BootJar> candidate) {
4656
if (this.currentArtifact == null) {
4757
add(candidate);
4858
}
4959
}
5060

51-
private void add(PublishArtifact artifact) {
52-
this.artifacts.remove(this.currentArtifact);
53-
this.artifacts.add(artifact);
54-
this.currentArtifact = artifact;
61+
private void add(TaskProvider<? extends Jar> artifact) {
62+
this.configuration.getArtifacts().remove(this.currentArtifact);
63+
this.currentArtifact = this.handler.add(this.configuration.getName(), artifact);
5564
}
5665

5766
@Override
5867
public TaskDependency getBuildDependencies() {
59-
return this.artifacts.getBuildDependencies();
68+
return this.configuration.getArtifacts().getBuildDependencies();
6069
}
6170

6271
}

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/SpringBootPlugin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ private Configuration createBootArchivesConfiguration(Project project) {
116116
}
117117

118118
private void registerPluginActions(Project project, Configuration bootArchives) {
119-
SinglePublishedArtifact singlePublishedArtifact = new SinglePublishedArtifact(bootArchives.getArtifacts());
119+
SinglePublishedArtifact singlePublishedArtifact = new SinglePublishedArtifact(bootArchives,
120+
project.getArtifacts());
120121
@SuppressWarnings("deprecation")
121122
List<PluginApplicationAction> actions = Arrays.asList(new JavaPluginAction(singlePublishedArtifact),
122123
new WarPluginAction(singlePublishedArtifact), new MavenPluginAction(bootArchives.getUploadTaskName()),

spring-boot-project/spring-boot-tools/spring-boot-gradle-plugin/src/main/java/org/springframework/boot/gradle/plugin/WarPluginAction.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import org.gradle.api.artifacts.Configuration;
2525
import org.gradle.api.artifacts.ConfigurationContainer;
2626
import org.gradle.api.file.FileCollection;
27-
import org.gradle.api.internal.artifacts.dsl.LazyPublishArtifact;
2827
import org.gradle.api.plugins.BasePlugin;
2928
import org.gradle.api.plugins.WarPlugin;
3029
import org.gradle.api.provider.Provider;
@@ -107,8 +106,7 @@ private void configureBootBuildImageTask(Project project, TaskProvider<BootWar>
107106
}
108107

109108
private void configureArtifactPublication(TaskProvider<BootWar> bootWar) {
110-
LazyPublishArtifact artifact = new LazyPublishArtifact(bootWar);
111-
this.singlePublishedArtifact.addWarCandidate(artifact);
109+
this.singlePublishedArtifact.addWarCandidate(bootWar);
112110
}
113111

114112
}

0 commit comments

Comments
 (0)