Add dependencies to inputs in bootRepackge

See gh-1113
pull/1132/merge
Dave Syer 11 years ago
parent 1bcc136374
commit 08ae390696

@ -89,11 +89,12 @@ public class RepackagePluginFeatures implements PluginFeatures {
@Override @Override
public void execute(Jar archive) { public void execute(Jar archive) {
if ("".equals(archive.getClassifier())) { if ("".equals(archive.getClassifier())) {
setClassifier(this.task, archive); setClassifier(archive);
File file = archive.getArchivePath(); File file = archive.getArchivePath();
String classifier = this.task.getClassifier(); String classifier = this.task.getClassifier();
if (classifier != null) { if (classifier != null) {
this.task.getInputs().file(archive); this.task.getInputs().file(archive);
task.getInputs().file(task.getDependencies());
String withClassifer = file.getName(); String withClassifer = file.getName();
withClassifer = StringUtils.stripFilenameExtension(withClassifer) withClassifer = StringUtils.stripFilenameExtension(withClassifer)
+ "-" + classifier + "." + "-" + 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(); Project project = task.getProject();
String classifier = null; String classifier = null;
SpringBootPluginExtension extension = project.getExtensions().getByType( SpringBootPluginExtension extension = project.getExtensions().getByType(

@ -18,6 +18,8 @@ package org.springframework.boot.gradle.repackage;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.gradle.api.Action; 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.TaskAction;
import org.gradle.api.tasks.bundling.Jar; import org.gradle.api.tasks.bundling.Jar;
import org.springframework.boot.gradle.SpringBootPluginExtension; 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.boot.loader.tools.Repackager;
import org.springframework.util.FileCopyUtils; import org.springframework.util.FileCopyUtils;
@ -75,6 +79,30 @@ public class RepackageTask extends DefaultTask {
@TaskAction @TaskAction
public void repackage() { 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(); Project project = getProject();
SpringBootPluginExtension extension = project.getExtensions().getByType( SpringBootPluginExtension extension = project.getExtensions().getByType(
SpringBootPluginExtension.class); SpringBootPluginExtension.class);
@ -88,7 +116,7 @@ public class RepackageTask extends DefaultTask {
else if (extension.getCustomConfiguration() != null) { else if (extension.getCustomConfiguration() != null) {
libraries.setCustomConfigurationName(extension.getCustomConfiguration()); libraries.setCustomConfigurationName(extension.getCustomConfiguration());
} }
project.getTasks().withType(Jar.class, new RepackageAction(extension, libraries)); return libraries;
} }
private class RepackageAction implements Action<Jar> { private class RepackageAction implements Action<Jar> {

Loading…
Cancel
Save