How to Fix “Unknown Host Exception: service.gradle.org” When Running gradlew.bat bootRun in VS Code

How to Fix "Unknown Host Exception: service.gradle.org" When Running gradlew.bat bootRun in VS Code

“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.


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:

  1. Open a browser and visit the Gradle services URL:
    https://services.gradle.org
  2. 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:

  1. 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
  2. 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:

    1. Open Settings (Ctrl+,).
    2. 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:

    1. Open the gradle-wrapper.properties file in your project under gradle/wrapper/.
    2. Check the distributionUrl value: Replace 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:

    1. Visit the Gradle Distributions Page.
    2. Download the required version (e.g., gradle-x.x-bin.zip).
    3. Place the file in your gradle/wrapper/ directory.
    4. 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!

    If you’re interested in exploring more grails framework resources and diving deeper into its features, click on this link to access additional tutorials, guides, and examples that will help you master grails framework!

    Leave a Reply

    Your email address will not be published. Required fields are marked *