Use a RegularFileProperty to configure BootBuildImage's input jar

Closes gh-20010
pull/20020/head
Andy Wilkinson 5 years ago
parent 199cea206f
commit bca98c5126

@ -101,7 +101,7 @@ final class JavaPluginAction implements PluginApplicationAction {
BootBuildImage.class); BootBuildImage.class);
buildImage.setDescription("Builds an OCI image of the application using the output of the bootJar task"); buildImage.setDescription("Builds an OCI image of the application using the output of the bootJar task");
buildImage.setGroup(BasePlugin.BUILD_GROUP); buildImage.setGroup(BasePlugin.BUILD_GROUP);
buildImage.from(bootJar); buildImage.getJar().set(bootJar.getArchiveFile());
} }
private void configureArtifactPublication(BootJar bootJar) { private void configureArtifactPublication(BootJar bootJar) {

@ -16,15 +16,14 @@
package org.springframework.boot.gradle.tasks.bundling; package org.springframework.boot.gradle.tasks.bundling;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.function.Supplier;
import org.gradle.api.DefaultTask; import org.gradle.api.DefaultTask;
import org.gradle.api.Project; import org.gradle.api.Project;
import org.gradle.api.Task; import org.gradle.api.Task;
import org.gradle.api.file.RegularFileProperty;
import org.gradle.api.tasks.Input; import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.Optional; import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.TaskAction; import org.gradle.api.tasks.TaskAction;
@ -46,7 +45,7 @@ import org.springframework.util.StringUtils;
*/ */
public class BootBuildImage extends DefaultTask { public class BootBuildImage extends DefaultTask {
private Supplier<File> jar; private RegularFileProperty jar;
private String imageName; private String imageName;
@ -58,22 +57,17 @@ public class BootBuildImage extends DefaultTask {
private boolean verboseLogging; private boolean verboseLogging;
/** public BootBuildImage() {
* Configures this task to create an image from the given {@code bootJar} task. This this.jar = getProject().getObjects().fileProperty();
* task is also configured to depend upon the given task.
* @param bootJar the fat jar from which the image should be created.
*/
public void from(BootJar bootJar) {
dependsOn(bootJar);
this.jar = () -> bootJar.getArchiveFile().get().getAsFile();
} }
/** /**
* Configures this task to create an image from the given jar file. * Returns the property for the jar file from which the image will be built.
* @param jar the jar from which the image should be created. * @return the jar property
*/ */
public void from(File jar) { @Input
this.jar = () -> jar; public RegularFileProperty getJar() {
return this.jar;
} }
/** /**
@ -192,8 +186,8 @@ public class BootBuildImage extends DefaultTask {
} }
BuildRequest createRequest() { BuildRequest createRequest() {
BuildRequest request = customize( BuildRequest request = customize(BuildRequest.of(determineImageReference(),
BuildRequest.of(determineImageReference(), (owner) -> new ZipFileTarArchive(this.jar.get(), owner))); (owner) -> new ZipFileTarArchive(this.jar.get().getAsFile(), owner)));
return request; return request;
} }

Loading…
Cancel
Save