|
|
@ -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> {
|
|
|
|