@Contract("null -> null")
  public static BuildEnvironment convertBuildEnvironment(@Nullable BuildEnvironment buildEnvironment) {
    if (buildEnvironment == null || buildEnvironment instanceof InternalBuildEnvironment) {
      return buildEnvironment;
    }
    return new InternalBuildEnvironment(
      () -> {
        BuildIdentifier buildIdentifier = buildEnvironment.getBuildIdentifier();
        return new InternalBuildIdentifier(buildIdentifier.getRootDir());
      },
      () -> {
        GradleEnvironment gradle = buildEnvironment.getGradle();
        return new InternalGradleEnvironment(gradle.getGradleUserHome(), gradle.getGradleVersion());
      },
      () -> {
        JavaEnvironment java = buildEnvironment.getJava();
        return new InternalJavaEnvironment(java.getJavaHome(), java.getJvmArguments());
      }
    );
  }
@Contract("null -> null")
  public static BuildEnvironment convertBuildEnvironment(@Nullable BuildEnvironment buildEnvironment)