-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGradleWrapperBootstrap.java
More file actions
40 lines (34 loc) · 1.51 KB
/
Copy pathGradleWrapperBootstrap.java
File metadata and controls
40 lines (34 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.zip.ZipInputStream;
public class GradleWrapperBootstrap {
public static void main(String[] args) throws Exception {
String gradleVersion = "7.4.2";
String zipUrl = "https://services.gradle.org/distributions/gradle-" + gradleVersion + "-bin.zip";
String zipFile = "gradle-" + gradleVersion + "-bin.zip";
String wrapperJar = "gradle-wrapper-" + gradleVersion + ".jar";
String wrapperDir = "gradle/wrapper";
// Download the Gradle distribution
try (var in = new URL(zipUrl).openStream()) {
Files.copy(in, Paths.get(zipFile), StandardCopyOption.REPLACE_EXISTING);
}
// Create the wrapper directory
Files.createDirectories(Paths.get(wrapperDir));
// Extract the wrapper JAR from the zip
try (var zin = new ZipInputStream(Files.newInputStream(Paths.get(zipFile)))) {
var entry = zin.getNextEntry();
while (entry != null) {
if (entry.getName().endsWith(wrapperJar)) {
Files.copy(zin, Paths.get(wrapperDir, "gradle-wrapper.jar"), StandardCopyOption.REPLACE_EXISTING);
break;
}
entry = zin.getNextEntry();
}
}
// Clean up the downloaded zip file
Files.delete(Paths.get(zipFile));
System.out.println("Gradle wrapper setup complete.");
}
}