“Learn how to fix the “Unknown Host Exception: service.gradle.org” error when running gradlew.bat bootRun
in VS Code. This detailed guide covers proxy configuration, offline mode, manual Gradle setup, DNS flushing, and more to resolve Gradle network issues effectively.”
Encountering the error “Unknown Host Exception: service.gradle.org” while running gradlew.bat bootRun
in VS Code can be frustrating, especially when working with the Grails framework or other Gradle-based projects. This error occurs when Gradle cannot connect to its distribution server due to network issues, proxy settings, or firewall restrictions.
In this guide, I’ll walk you through a detailed, step-by-step solution to fix this issue, tailored for VS Code users. Each step includes clear explanations and code snippets formatted for WordPress with colorful HTML decoration for easy use.
Table of Contents
Why Does This Error Occur?
This error arises because Gradle is unable to resolve dependencies or download the necessary Gradle distribution files. Common causes include:
- Network issues: No internet connection or unstable network.
- Firewall restrictions: Blocking access to Gradle services.
- Proxy settings: Corporate proxies interfering with connections.
Step-by-Step Solution
1. Verify Your Internet Connection
The first step is to confirm that your system is connected to the internet:
- Open a browser and visit the Gradle services URL:
https://services.gradle.org - If the URL is inaccessible, troubleshoot your internet connection or contact your network administrator.
2. Configure Proxy Settings for Gradle
If you are behind a corporate proxy, Gradle needs to know the proxy details to establish connections.
Steps to Add Proxy Settings:
- Open or create a
gradle.properties
file in either of these locations:- Project-specific:
project_root/gradle.properties
- Global:
C:\Users\<YourUsername>\.gradle\gradle.properties
- Project-specific:
- Add the following properties to the file:
systemProp.http.proxyHost=proxy_host
systemProp.http.proxyPort=proxy_port
systemProp.https.proxyHost=proxy_host
systemProp.https.proxyPort=proxy_port
3. Save the file and retry running:
gradlew.bat bootRun
3. Configure Proxy in VS Code
If you use VS Code’s terminal, it may also require proxy settings.
Steps to Configure Proxy in VS Code:
- Open Settings (
Ctrl+,
). - Search for “proxy” and update these settings: helps if your proxy uses untrusted SSL certificates
"http.proxy": "http://proxy_host:proxy_port",
"https.proxy": "https://proxy_host:proxy_port",
"http.proxyStrictSSL": false
4. Run Gradle in Offline Mode (Temporary Fix)
If you have already built the project and downloaded dependencies previously, you can bypass network issues by running Gradle offline.
Command:
gradlew.bat bootRun --offline
5. Verify gradle-wrapper.properties
Ensure the Gradle wrapper is pointing to the correct distribution URL.
Steps:
- Open the
gradle-wrapper.properties
file in your project undergradle/wrapper/
. - Check the
distributionUrl
value:x.x
with the required Gradle version.
distributionUrl=https\://services.gradle.org/distributions/gradle-x.x-bin.zip
6. Flush DNS Cache
If DNS issues are causing connectivity problems, flushing the DNS cache can help.
Windows Command:
ipconfig /flushdns
macOS/Linux Command:
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder
7. Manually Download Gradle Distribution
If automatic downloading fails, you can download Gradle manually and reference it locally.
Steps:
- Visit the Gradle Distributions Page.
- Download the required version (e.g.,
gradle-x.x-bin.zip
). - Place the file in your
gradle/wrapper/
directory. - Update the
gradle-wrapper.properties
file:
distributionUrl=file:///path/to/gradle-x.x-bin.zip
8. Debugging Network Issues
If the issue persists, enable detailed logging to identify the root cause.
Command:
gradlew.bat bootRun --stacktrace --debug
Review the logs for clues about connectivity or configuration problems.
9. Upgrade Gradle Wrapper
Using an outdated Gradle version can also lead to issues. Update the Gradle wrapper with the following command:
gradlew.bat wrapper --gradle-version <new-version>
Replace <new-version>
with the latest stable version (e.g., 8.1
).
10. Whitelist Gradle Service URLs
If you’re behind a corporate firewall, ensure the following URLs are accessible:
https://services.gradle.org
https://repo.gradle.org
Ask your network administrator to whitelist these URLs.
Conclusion
By following the steps outlined in this guide, you should be able to resolve the “Unknown Host Exception: service.gradle.org” error and run your Grails application successfully in VS Code. From proxy configurations to offline modes and manual Gradle setups, these solutions cover all potential scenarios.
If you still encounter issues, feel free to share your logs or ask for further assistance in the comments!