gradle/gradle · error · IllegalStateException
Unable to determine scala version
Error message
Unable to determine scala version
What it means
ZincScalaCompilerFactory.getScalaVersion opens compiler.properties from the classloader holding the Scala compiler and reads the version.number property to select the correct compiler bridge and Zinc setup. Any IOException while loading the stream is rethrown as IllegalStateException('Unable to determine scala version'), meaning the Scala compiler jar on the classpath does not carry a readable compiler.properties.
Source
Thrown at platforms/jvm/scala-compiler-worker/src/main/java/org/gradle/api/internal/tasks/scala/ZincScalaCompilerFactory.java:252
});
}
private static File findFile(String prefix, ClassPath classpath) {
for (File f : classpath.getAsFiles()) {
if (f.getName().startsWith(prefix)) {
return f;
}
}
throw new IllegalStateException(String.format("Cannot find any files starting with %s in %s", prefix, classpath.getAsFiles()));
}
private static String getScalaVersion(ClassLoader scalaClassLoader) {
try {
Properties props = new Properties();
props.load(scalaClassLoader.getResourceAsStream("compiler.properties"));
return props.getProperty("version.number");
} catch (IOException e) {
throw new IllegalStateException("Unable to determine scala version");
}
}
}
View on GitHub (pinned to 534f27719b)
Solutions
- Check the caused-by IOException and inspect the scala-compiler jar on the classpath (jar tf scala-compiler-*.jar | grep compiler.properties)
- Purge the cached artifact: ./gradlew build --refresh-dependencies (or delete it under ~/.gradle/caches/modules-2) so a clean copy is downloaded
- Replace stripped/forked scala-compiler with the official org.scala-lang:scala-compiler artifact of the same version
- If you must publish a custom Scala distribution, ensure compiler.properties with version.number is preserved in the jar
Example fix
// before: locally patched distribution without compiler.properties implementation 'com.example:scala-compiler-patched:2.13.14' // after: official distribution keeps compiler.properties intact implementation 'org.scala-lang:scala-compiler:2.13.14' implementation 'org.scala-lang:scala-library:2.13.14'
Defensive patterns
Strategy: validation
Validate before calling
// verify compiler.properties exists and is readable inside every scala-compiler jar
configurations.matching { it.name.toLowerCase().contains('scala') }.all { cfg ->
cfg.files.findAll { it.name.startsWith('scala-compiler') }.each { jar ->
assert new java.util.zip.ZipFile(jar).getEntry('compiler.properties') != null : \
"${jar} lacks compiler.properties"
}
} Prevention
- Use official org.scala-lang artifacts instead of repackaged Scala distributions
- When publishing custom Scala jars, keep META-INF/compiler.properties with version.number intact
- After network hiccups, build with --refresh-dependencies to replace possibly truncated jars
- Cache poisoning check: delete suspect artifacts under ~/.gradle/caches/modules-2 and re-resolve
When it happens
Trigger: The scala-compiler jar on scalaClasspath is corrupted (truncated download), was repackaged/stripped without compiler.properties, or is a non-standard home-grown Scala build whose distribution omits the properties file.
Common situations: Locally published or shaded scala-compiler artifacts missing metadata; broken caches after an interrupted download; a proxy serving HTML error pages as jars; using a patched/forked Scala distribution.
Related errors
- Failed to instantiate ClassLoaderCache
- Failed create instance of the scala compiler
- Cannot find any files starting with %s in %s
- The version of 'scala-library' was changed while using the d
- Unable to determine Groovy version.
AI-assisted analysis of gradle/gradle@534f27719b (2026-08-22).
Data as JSON: /api/errors/56a91a09ffafe5d6.
Report an issue: GitHub.