Skip to content

Commit 29f207c

Browse files
docs: add explanation for Gradle wrapper classpath removal
Co-authored-by: jiajingjing2016 <137744850+jiajingjing2016@users.noreply.github.com>
1 parent fc6773a commit 29f207c

File tree

1 file changed

+126
-0
lines changed

1 file changed

+126
-0
lines changed

docs/GRADLE_WRAPPER_CHANGES.md

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# Gradle Wrapper Changes - Classpath Removal
2+
3+
## Overview
4+
5+
During the upgrade from Gradle 8.14.2 to Gradle 9.3.1, you may notice that the `CLASSPATH` variable and `-classpath` argument were removed from the Gradle wrapper scripts (`gradlew`, `gradlew.bat`, `android/gradlew`, and `android/gradlew.bat`).
6+
7+
**This is an intentional and expected change made by Gradle, not a mistake.**
8+
9+
## What Changed
10+
11+
### Before (Gradle 8.14.2 and earlier)
12+
```bash
13+
# In gradlew
14+
CLASSPATH="\\\"\\\""
15+
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
16+
17+
# Command execution
18+
java -classpath "$CLASSPATH" -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" "$@"
19+
```
20+
21+
```batch
22+
@rem In gradlew.bat
23+
set CLASSPATH=
24+
25+
@rem Command execution
26+
java -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
27+
```
28+
29+
### After (Gradle 9.3.1)
30+
```bash
31+
# In gradlew
32+
# CLASSPATH variables removed
33+
34+
# Command execution
35+
java -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" "$@"
36+
```
37+
38+
```batch
39+
@rem In gradlew.bat
40+
@rem CLASSPATH variables removed
41+
42+
@rem Command execution
43+
java -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
44+
```
45+
46+
## Why Was This Changed?
47+
48+
### 1. Executable JAR Conversion
49+
Starting with Gradle 8.14, the Gradle wrapper JAR (`gradle-wrapper.jar`) was updated to be a fully executable JAR with a `Main-Class` manifest entry. This means:
50+
- The JAR can be run directly with `java -jar gradle-wrapper.jar`
51+
- No need to manually specify the classpath or main class
52+
- Simpler and more reliable execution
53+
54+
### 2. Benefits
55+
56+
#### Simplicity
57+
- **Fewer moving parts**: Reduces the complexity of the wrapper script
58+
- **Less error-prone**: Eliminates potential issues with classpath construction
59+
- **Cleaner code**: More maintainable wrapper scripts
60+
61+
#### Cross-Platform Compatibility
62+
- **Consistent behavior**: Works the same across all platforms and Java versions
63+
- **Fewer escaping issues**: Avoids platform-specific path quoting/escaping problems
64+
- **Standard Java practice**: Uses the industry-standard approach for running Java applications
65+
66+
#### Security and Maintainability
67+
- **Reduced attack surface**: Simpler scripts are easier to audit and secure
68+
- **Better maintainability**: Easier for Gradle team to maintain and improve
69+
- **Future-proof**: Aligns with modern Java conventions
70+
71+
### 3. Technical Details
72+
73+
The old approach manually constructed a classpath and specified the main class:
74+
```bash
75+
java -cp gradle-wrapper.jar org.gradle.wrapper.GradleWrapperMain [args...]
76+
```
77+
78+
The new approach uses the executable JAR's manifest:
79+
```bash
80+
java -jar gradle-wrapper.jar [args...]
81+
```
82+
83+
The `gradle-wrapper.jar` manifest now contains:
84+
```
85+
Main-Class: org.gradle.wrapper.GradleWrapperMain
86+
```
87+
88+
## Impact on This Project
89+
90+
When we upgraded to Gradle 9.3.1:
91+
1. Updated `gradle/wrapper/gradle-wrapper.jar` (binary file)
92+
2. Updated `gradle/wrapper/gradle-wrapper.properties` (version string)
93+
3. Regenerated wrapper scripts (`gradlew` and `gradlew.bat`)
94+
4. Applied the same changes to the Android subdirectory
95+
96+
The classpath removal was automatic when we ran:
97+
```bash
98+
./gradlew wrapper --gradle-version 9.3.1
99+
```
100+
101+
## No Action Required
102+
103+
This change is:
104+
-**Intentional**: Made by the Gradle project
105+
-**Standard**: Part of the normal Gradle upgrade process
106+
-**Safe**: Tested and used by millions of projects
107+
-**Recommended**: Following Gradle best practices
108+
109+
If you see these changes in a diff or pull request, they are expected and should not be reverted.
110+
111+
## References
112+
113+
- [Gradle 9.3.1 Release Notes](https://docs.gradle.org/9.3.1/release-notes.html)
114+
- [Upgrading within Gradle 8.x](https://docs.gradle.org/current/userguide/upgrading_version_8.html)
115+
- [Upgrading within Gradle 9.x](https://docs.gradle.org/current/userguide/upgrading_version_9.html)
116+
- [Gradle Wrapper Documentation](https://docs.gradle.org/current/userguide/gradle_wrapper.html)
117+
118+
## Related Changes in This PR
119+
120+
This classpath removal was part of a larger upgrade effort that included:
121+
1. Gradle wrapper: 8.14.2 → 9.3.1 (root and android directories)
122+
2. Android Gradle Plugin: 8.13.2 → 9.0.0
123+
3. CI configuration updates to use JVM 17 for Gradle while maintaining Java 8 bytecode compatibility
124+
4. Java compiler memory configuration for the java-8 build
125+
126+
See the PR description for complete details on all changes.

0 commit comments

Comments
 (0)