Gradle Download File From Url [top] May 2026
If you want full control or need to avoid plugins entirely, you can write a custom task using standard Java/Groovy URL streams.
tasks.register("downloadWithAnt") { doLast { ant.get(src: 'https://example.com', dest: buildDir) } } Use code with caution. : No extra dependencies; very lightweight.
: Always wrap these in a proper Gradle task with defined outputs to ensure they interact correctly with Gradle's up-to-date checking (caching). Method 4: Downloading with Authentication gradle download file from url
: Use a java.net.Authenticator or manually add an Authorization header to your request if using more modern HTTP clients like java.net.http.HttpClient . Comparison Table Ease of Use Key Features Plugin Production builds Progress info, auth, checksums Ant get Quick tasks Included in core Gradle Manual Code Minimalist builds Zero dependencies
: Lacks advanced features like progress reporting or easy caching compared to specialized plugins. Method 3: Custom Task with Native Java/Groovy If you want full control or need to
: Handles multiple files, supports HTTP basic authentication, and can verify checksums. Method 2: Using the Built-in Ant get Task
When the file is behind a secure URL, you can pass credentials using headers or specific plugin parameters. : Always wrap these in a proper Gradle
Downloading files from a URL is a common requirement in Gradle build scripts, whether you're fetching a specific tool, a configuration file, or raw data assets. While Gradle doesn't have a dedicated "download" core task, there are several effective ways to achieve this using built-in Ant tasks, custom Groovy/Kotlin code, or specialized community plugins.