gradle/gradle · error · BrokenResultException
Could not determine %s metadata: %s produced unexpected outp
Error message
Could not determine %s metadata: %s produced unexpected output.
What it means
SwiftcMetadataProvider runs `swiftc --version` and scans stdout for a line containing 'Swift version', parsing the version from token index 2 ('Swift version 4.0.2 (...)') or index 3 when the line starts with 'Apple' ('Apple Swift version 4.0.2 (...)'). If no line matches, BrokenResultException 'Could not determine SwiftC metadata: <binary> produced unexpected output' is thrown.
Source
Thrown at platforms/native/platform-native/src/main/java/org/gradle/nativeplatform/toolchain/internal/swift/metadata/SwiftcMetadataProvider.java:78
@Override
protected SwiftcMetadata parseCompilerOutput(String stdout, String stderr, File swiftc, List<File> path) {
BufferedReader reader = new BufferedReader(new StringReader(stdout));
try {
String line;
while ((line = reader.readLine()) != null) {
if (line.contains("Swift version")) {
String[] tokens = line.split(" ");
// Assuming format: 'Swift version 4.0.2 (...)'
int i = 2;
if ("Apple".equals(tokens[0])) {
// Actual format: 'Apple Swift version 4.0.2 (...)'
i++;
}
VersionNumber version = VersionNumber.parse(tokens[i]);
return new DefaultSwiftcMetadata(line, version);
}
}
throw new BrokenResultException(String.format("Could not determine %s metadata: %s produced unexpected output.", getCompilerType().getDescription(), swiftc.getName()));
} catch (IOException e) {
// Should not happen when reading from a StringReader
throw UncheckedException.throwAsUncheckedException(e);
}
}
private static class DefaultSwiftcMetadata implements SwiftcMetadata {
private final String versionString;
private final VersionNumber version;
DefaultSwiftcMetadata(String versionString, VersionNumber version) {
this.versionString = versionString;
this.version = version;
}
@Override
public String getVendor() {
return versionString;View on GitHub (pinned to 534f27719b)
Solutions
- Run `swiftc --version` yourself and check a line contains 'Swift version <n.n.n>'; if it reads 'Swift compiler version ...', switch to a release toolchain (banner 'Swift version ...').
- Point the Swift toolchain configuration at the real swiftc binary, not a wrapper.
- Upgrade Gradle - newer metadata providers parse development-snapshot banners too.
Example fix
# before $ swiftc --version Swift compiler version 6.0 (swift-6.0-DEVELOPMENT) # no 'Swift version' line -> error # after: install/use a release toolchain $ swiftc --version Swift version 5.10 (swift-5.10-RELEASE) Target: x86_64-unknown-linux-gnu
Defensive patterns
Strategy: validation
Validate before calling
def out = 'swiftc --version'.execute().in.text
if (!out.readLines().any { it.contains('Swift version') }) {
throw new GradleException('swiftc --version has no "Swift version" line (dev snapshot or wrapper?); install a release toolchain')
} Prevention
- Use release Swift toolchains with Gradle; development snapshots print 'Swift compiler version' banners this parser rejects.
- Point the Swift toolchain path at the real swiftc, not a wrapper script.
- Add a CI preflight running swiftc --version and asserting the banner format.
When it happens
Trigger: A swiftc whose --version banner does not contain the literal substring 'Swift version': development snapshots print 'Swift compiler version 6.0-dev ...' (the word 'compiler' breaks the match); non-Apple custom builds with a different banner; tokens[2]/tokens[3] not being a parseable version; empty stdout when the binary is a broken shim.
Common situations: Using a swift.org DEVELOPMENT/main-snapshot toolchain (banner 'Swift compiler version ...') with an older Gradle; aliasing swiftc to a wrapper that swallows stdout; Swift toolchains from unusual vendors on CI.
Related errors
- Swift compiler version '%s' doesn't support Swift language v
- Library Path not yet supported on Swiftc
- '%s' is not a valid Gradle version string (examples: '9.0.0'
- Swift language version is unknown for the specified Swift co
- Could not determine the name of {displayName}: unknown compo
AI-assisted analysis of gradle/gradle@534f27719b (2026-08-22).
Data as JSON: /api/errors/501749411bfbf565.
Report an issue: GitHub.