Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Runemoro/729fdf327147c2df1a8b48d07f3ce432 to your computer and use it in GitHub Desktop.
Save Runemoro/729fdf327147c2df1a8b48d07f3ce432 to your computer and use it in GitHub Desktop.
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import java.io.File;
import java.io.FileReader;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
public class DownloadLibs {
private static final String VERSION = "1.14";
public static void main(String[] args) throws Exception {
JsonElement json;
try (FileReader reader = new FileReader(VERSION + ".json")) {
json = new Gson().fromJson(reader, JsonElement.class);
}
Set<String> urls = new LinkedHashSet<>();
json.getAsJsonObject()
.getAsJsonArray("libraries")
.forEach(libraryJson -> urls.add(libraryJson
.getAsJsonObject()
.getAsJsonObject("downloads")
.getAsJsonObject("artifact")
.get("url")
.getAsString()));
new File(VERSION).mkdir();
for (String url : urls) {
System.out.println("Downloading " + url + "");
try (InputStream in = new URL(url).openStream()) {
String[] split = url.split("/");
Files.copy(in, new File(VERSION + "/" + split[split.length - 1]).toPath(), StandardCopyOption.REPLACE_EXISTING);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment