@Override public LazyCredentialsExtension configure(Closure c) { if (!Closure.class.isInstance(c.getDelegate()) || DefaultMavenArtifactRepository.class.isInstance(((Closure)c.getDelegate()))) { throw new IllegalStateException("This extension can only be used in maven repository config."); } LazyCredentials credentials = new LazyCredentials(project); Object originalDelegate = ((Closure)c.getDelegate()).getDelegate(); c.setResolveStrategy(Closure.DELEGATE_FIRST); c.setDelegate(credentials); c.call(); ((DefaultMavenArtifactRepository) originalDelegate).setConfiguredCredentials(credentials); return this; }
public static List<DefaultMavenArtifactRepository> getMavenRepositories(Project project) { List<DefaultMavenArtifactRepository> repos = new ArrayList<>(); PublishingExtension publishingExtension = getPublishingExtension(project); if (publishingExtension != null) { RepositoryHandler repositoryHandler = publishingExtension.getRepositories(); for (ArtifactRepository repo : repositoryHandler) { repos.add((DefaultMavenArtifactRepository)repo); } } return repos; }
public static boolean hasMavenRepository(Project project, String repoName) { for (DefaultMavenArtifactRepository repo : getMavenRepositories(project)) { if (repoName.equals(repo.getName())) { return true; } } return false; }