How to Fix Old ForgeGradle Versions Getting 400 Responses Downloading the Assets

So one time, I tried to set up the mod development workspace for Minecraft Forge 1.10.2. As usual, I ran gradlew setupDecompWorkspace eclipse. At getAssets task, however, the console fills up with errors:

java.io.IOException: Server returned HTTP response code: 400 for URL: http://resources.download.minecraft.net/...

Cause

It turns out that the problem occurs when the following conditions are met:

  1. Using an older version of ForgeGradle (before 3.0), which is required if you are working with older Minecraft versions, AND
  2. Either you never launched the version of Minecraft OR you put your .minecraft directory somewhere other than the default location (this was my case).

When getting the assets, ForgeGradle with first lookup your local .minecraft directory for them (at the default location), which fails under condition 2. Then, it falls back to downloading it from Minecraft's servers.

In ForgeGradle 2.3 and before, it tries to grab them from the following URL as defined here:

public static final String URL_ASSETS = "http://resources.download.minecraft.net";

However, the API seems to have been recently changed so it only accepts HTTPS connections. The requests are rejected because the URL specifies http protocol.

Solution

So, if you want to work with Forge on an old Minecraft version, what can you do?

You can fix it by making condition 2 not hold, therefore, the goal are to

  1. Have the assets downloaded
  2. Point ForgeGradle to the correct .minecraft location.

Goal 1

Make sure that you launched the Minecraft version at least once so that the assets are downloaded.

Goal 2

This applies to people who moved their .minecraft directory from the default locations, which is inside the directory pointed by APPDATA environment variable on Windows and the user's home directory on Linux/OSX.

You can therefore fix it by (temporarily) setting APPDATA (Windows) or user.home (Linux/OSX) environment variable to the parent directory of your .minecraft directory. Look up how to do it on your OS and shell. Since I was on Windows and Powershell, I ran the following:

$env:APPDATA="Z:\path\to\parent"

This causes ForgeGradle to match Z:\path\to\parent\.minecraft. If it finds that you have locally-downloaded assets for the version, it can take them from there.

Done

Finally, run the command gradlew setupDecompWorkspace eclipse once again. No HTTP errors now, because it no longer gets them from remote.