dagger/dagger · error · IllegalStateException

Could not retrieve dagger version

Error message

Could not retrieve dagger version

What it means

This IllegalStateException is thrown by the Java SDK's Provisioning.getCLIVersion() when it fails to read the VERSION field from the generated io.dagger.client.Version class via reflection. The Version class is generated during codegen; if it is missing, malformed, or its field is absent, reflection fails and the SDK wraps the exception. It means the SDK's client version metadata could not be resolved, which typically indicates the generated client code is stale or incomplete.

Solutions

  1. Run the SDK codegen (dagger develop / maven codegen plugin) to regenerate io.dagger.client.Version with the VERSION field
  2. Verify Version.java exists under src/main/java/io/dagger/client/ and contains `public static final String VERSION = ...`; regenerate if missing
  3. Check that your build packaging (maven-shade/jar) includes the generated io.dagger.client.Version class and does not relocate it
  4. Align the dagger-codegen-maven-plugin and dagger-java-sdk versions in your pom.xml so codegen output matches the client
  5. Enable the cause's stack trace (e.getCause()) to see whether it was ClassNotFoundException vs NoSuchFieldException and fix accordingly

Example fix

// before: Version.java missing or empty
// after: regenerate it
// generated file: src/main/java/io/dagger/client/Version.java
public final class Version {
  public static final String VERSION = "0.18.0";
}
Defensive patterns

Strategy: try-catch

Validate before calling

// before provisioning
try {
  Class<?> v = Class.forName("io.dagger.client.Version");
  Object ver = v.getField("VERSION").get(null);
  if (ver == null || ((String) ver).isEmpty()) throw new IllegalStateException("empty VERSION");
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) {
  throw new IllegalStateException("SDK codegen output missing; run codegen", e);
}

Type guard

static boolean hasVersionClass() {
  try {
    return Class.forName("io.dagger.client.Version").getField("VERSION") != null;
  } catch (Exception e) { return false; }
}

Try / catch

try {
  String version = Provisioning.getCLIVersion();
} catch (IllegalStateException e) {
  // log e.getCause() (ClassNotFound vs NoSuchField) and regenerate SDK codegen
}

Prevention

When it happens

Trigger: Calling Provisioning.getCLIVersion() (directly or indirectly during EngineConnection/provisioning setup) when the io.dagger.client.Version class is not on the classpath, the VERSION String field does not exist, the field is not static/accessible, or Class.forName fails because codegen was never run or produced an older layout.

Common situations: Building the SDK from source without running the codegen step that generates Version.java; mixing SDK versions where a custom client jar was compiled against a different codegen output; fat-jar/shading configurations that exclude or rename the generated Version class; IDE incremental builds that skipped annotation/codegen processing.

Related errors


AI-assisted analysis of dagger/dagger@82ba2681db (2026-09-05). Data as JSON: /api/errors/f75be9e24aea098c. Report an issue: GitHub.

Appendix: source

Thrown at sdk/java/dagger-java-sdk/src/main/java/io/dagger/client/engineconn/Provisioning.java:16

package io.dagger.client.engineconn;

class Provisioning {

  /**
   * Returns the Dagger version
   *
   * @return the Dagger version
   */
  static String getCLIVersion() {
    // Retrieve the version by refection to avoid package cyclic dependency
    try {
      return (String) Class.forName("io.dagger.client.Version").getField("VERSION").get(null);
    } catch (Exception e) {
      // Must not fail
      throw new IllegalStateException("Could not retrieve dagger version", e);
    }
  }

  /**
   * Returns the SDK version
   *
   * @return the SDK version
   */
  static String getSDKVersion() {
    // This value is replaced during build phase with the POM project.version property
    return "__PLACEHOLDER__";
  }
}

View on GitHub (pinned to 82ba2681db)