{"record":{"id":"f75be9e24aea098c","repo":"dagger/dagger","slug":"could-not-retrieve-dagger-version","errorCode":null,"errorMessage":"Could not retrieve dagger version","messagePattern":"Could not retrieve dagger version","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sdk/java/dagger-java-sdk/src/main/java/io/dagger/client/engineconn/Provisioning.java","lineNumber":16,"sourceCode":"package io.dagger.client.engineconn;\n\nclass Provisioning {\n\n  /**\n   * Returns the Dagger version\n   *\n   * @return the Dagger version\n   */\n  static String getCLIVersion() {\n    // Retrieve the version by refection to avoid package cyclic dependency\n    try {\n      return (String) Class.forName(\"io.dagger.client.Version\").getField(\"VERSION\").get(null);\n    } catch (Exception e) {\n      // Must not fail\n      throw new IllegalStateException(\"Could not retrieve dagger version\", e);\n    }\n  }\n\n  /**\n   * Returns the SDK version\n   *\n   * @return the SDK version\n   */\n  static String getSDKVersion() {\n    // This value is replaced during build phase with the POM project.version property\n    return \"__PLACEHOLDER__\";\n  }\n}\n","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/dagger/dagger/blob/82ba2681dbe30d3547a1dc50ea495900ab5b6047/sdk/java/dagger-java-sdk/src/main/java/io/dagger/client/engineconn/Provisioning.java#L1-L30","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run the SDK codegen (dagger develop / maven codegen plugin) to regenerate io.dagger.client.Version with the VERSION field","Verify Version.java exists under src/main/java/io/dagger/client/ and contains `public static final String VERSION = ...`; regenerate if missing","Check that your build packaging (maven-shade/jar) includes the generated io.dagger.client.Version class and does not relocate it","Align the dagger-codegen-maven-plugin and dagger-java-sdk versions in your pom.xml so codegen output matches the client","Enable the cause's stack trace (e.getCause()) to see whether it was ClassNotFoundException vs NoSuchFieldException and fix accordingly"],"exampleFix":"// before: Version.java missing or empty\n// after: regenerate it\n// generated file: src/main/java/io/dagger/client/Version.java\npublic final class Version {\n  public static final String VERSION = \"0.18.0\";\n}","handlingStrategy":"try-catch","validationCode":"// before provisioning\ntry {\n  Class<?> v = Class.forName(\"io.dagger.client.Version\");\n  Object ver = v.getField(\"VERSION\").get(null);\n  if (ver == null || ((String) ver).isEmpty()) throw new IllegalStateException(\"empty VERSION\");\n} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) {\n  throw new IllegalStateException(\"SDK codegen output missing; run codegen\", e);\n}","typeGuard":"static boolean hasVersionClass() {\n  try {\n    return Class.forName(\"io.dagger.client.Version\").getField(\"VERSION\") != null;\n  } catch (Exception e) { return false; }\n}","tryCatchPattern":"try {\n  String version = Provisioning.getCLIVersion();\n} catch (IllegalStateException e) {\n  // log e.getCause() (ClassNotFound vs NoSuchField) and regenerate SDK codegen\n}","preventionTips":["Always run SDK codegen before packaging; verify Version.java is generated","Add a build-time check/test asserting io.dagger.client.Version.VERSION is non-empty","Ensure shade/jar plugins do not exclude or relocate io.dagger.client.**","Keep dagger-codegen-maven-plugin and dagger-java-sdk versions in lockstep"],"tags":["java","sdk","reflection","provisioning"],"backgroundTag":"sdk-version-metadata-missing","analyzedSha":"82ba2681dbe30d3547a1dc50ea495900ab5b6047","analyzedAt":"2026-09-05T07:21:37.930Z","contentChangedAt":"2026-09-05T07:21:37.930Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}