Java IOException when trying to execute gradle

I’m getting the following error when I’m executing gradle.bat or even gradle -version.

 FAILURE: Build failed with an exception.

* What went wrong:
java.io.IOException: The filename, directory name, or volume label syntax is incorrect

Environment details:
Gradle: 4.10.2
OS: Windows 10 Enterprise
JDK Version: “1.8.0_66”

I ran into this issue on a composite build using Gradle 8.14.4. In my case, the problem was caused by using subproject notation (:<subproject-name>) in the includeBuild() entry of the top-level settings.gradle.kts file.

For example, if I had the project structure:

| root
  | a
    | a0
    | a1
  | b 
    | b0
    | b1

the correct syntax for including these builds in root/settings.gradle.kts is:

// correct, no : prefix
includeBuild("a")
includeBuild("b")

If you use subproject notation (shown below), Gradle will throw java.io.IOException every time you execute gradlew, regardless of what tasks you specify.

// incorrect, throws java.io.IOException
includeBuild(":a")
includeBuild(":b")