mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-09-03 04:26:12 +08:00
Add dependencies to inputs in bootRepackge
See gh-1113
This commit is contained in:
parent
1bcc136374
commit
08ae390696
@ -89,11 +89,12 @@ public class RepackagePluginFeatures implements PluginFeatures {
|
||||
@Override
|
||||
public void execute(Jar archive) {
|
||||
if ("".equals(archive.getClassifier())) {
|
||||
setClassifier(this.task, archive);
|
||||
setClassifier(archive);
|
||||
File file = archive.getArchivePath();
|
||||
String classifier = this.task.getClassifier();
|
||||
if (classifier != null) {
|
||||
this.task.getInputs().file(archive);
|
||||
task.getInputs().file(task.getDependencies());
|
||||
String withClassifer = file.getName();
|
||||
withClassifer = StringUtils.stripFilenameExtension(withClassifer)
|
||||
+ "-" + classifier + "."
|
||||
@ -107,7 +108,7 @@ public class RepackagePluginFeatures implements PluginFeatures {
|
||||
|
||||
}
|
||||
|
||||
private void setClassifier(RepackageTask task, Jar archive) {
|
||||
private void setClassifier(Jar archive) {
|
||||
Project project = task.getProject();
|
||||
String classifier = null;
|
||||
SpringBootPluginExtension extension = project.getExtensions().getByType(
|
||||
|
@ -18,6 +18,8 @@ package org.springframework.boot.gradle.repackage;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.gradle.api.Action;
|
||||
@ -26,6 +28,8 @@ import org.gradle.api.Project;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
import org.gradle.api.tasks.bundling.Jar;
|
||||
import org.springframework.boot.gradle.SpringBootPluginExtension;
|
||||
import org.springframework.boot.loader.tools.LibraryCallback;
|
||||
import org.springframework.boot.loader.tools.LibraryScope;
|
||||
import org.springframework.boot.loader.tools.Repackager;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
@ -75,6 +79,30 @@ public class RepackageTask extends DefaultTask {
|
||||
|
||||
@TaskAction
|
||||
public void repackage() {
|
||||
Project project = getProject();
|
||||
SpringBootPluginExtension extension = project.getExtensions().getByType(
|
||||
SpringBootPluginExtension.class);
|
||||
ProjectLibraries libraries = getLibraries();
|
||||
project.getTasks().withType(Jar.class, new RepackageAction(extension, libraries));
|
||||
}
|
||||
|
||||
public File[] getDependencies() {
|
||||
ProjectLibraries libraries = getLibraries();
|
||||
final List<File> files = new ArrayList<File>();
|
||||
try {
|
||||
libraries.doWithLibraries(new LibraryCallback() {
|
||||
@Override
|
||||
public void library(File file, LibraryScope scope) throws IOException {
|
||||
files.add(file);
|
||||
}
|
||||
});
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("Cannot retrieve dependencies", e);
|
||||
}
|
||||
return files.toArray(new File[files.size()]);
|
||||
}
|
||||
|
||||
private ProjectLibraries getLibraries() {
|
||||
Project project = getProject();
|
||||
SpringBootPluginExtension extension = project.getExtensions().getByType(
|
||||
SpringBootPluginExtension.class);
|
||||
@ -88,7 +116,7 @@ public class RepackageTask extends DefaultTask {
|
||||
else if (extension.getCustomConfiguration() != null) {
|
||||
libraries.setCustomConfigurationName(extension.getCustomConfiguration());
|
||||
}
|
||||
project.getTasks().withType(Jar.class, new RepackageAction(extension, libraries));
|
||||
return libraries;
|
||||
}
|
||||
|
||||
private class RepackageAction implements Action<Jar> {
|
||||
|
Loading…
Reference in New Issue
Block a user