private static boolean shouldStoreCredentials()

in artifactregistry-gradle-plugin/src/main/java/com/google/cloud/artifactregistry/gradle/plugin/ArtifactRegistryGradlePlugin.java [196:217]


  private static boolean shouldStoreCredentials(DefaultMavenArtifactRepository repo) {

    try {
      Method getConfiguredCredentials = DefaultMavenArtifactRepository.class
          .getMethod("getConfiguredCredentials");

      // This is for Gradle < 6.6. Once we no longer support versions of Gradle before 6.6
      if (getConfiguredCredentials.getReturnType().equals(Credentials.class)) {
        Credentials existingCredentials = (Credentials) getConfiguredCredentials.invoke(repo);
        return existingCredentials == null;
      } else if (getConfiguredCredentials.getReturnType().equals(Property.class)) {
        Property<?> existingCredentials = (Property<?>) getConfiguredCredentials.invoke(repo);
        return !existingCredentials.isPresent();
      } else {
        logger.warn("Error determining Gradle credentials API; expect authentication errors");
        return false;
      }
    } catch (ReflectiveOperationException e) {
      logger.warn("Error determining Gradle credentials API; expect authentication errors", e);
      return false;
    }
  }