Skip to content

Instantly share code, notes, and snippets.

@liangzai-cool
Created January 19, 2017 07:57
Show Gist options
  • Save liangzai-cool/94b6e33ba946881af69fe4194f541453 to your computer and use it in GitHub Desktop.
Save liangzai-cool/94b6e33ba946881af69fe4194f541453 to your computer and use it in GitHub Desktop.
Using plugins in init scripts.
apply plugin:EnterpriseRepositoryPlugin
class EnterpriseRepositoryPlugin implements Plugin<Gradle> {
private static String ENTERPRISE_REPOSITORY_URL = "https://my.repository.com/repository/maven-public/"
void apply(Gradle gradle) {
// ONLY USE ENTERPRISE REPO FOR DEPENDENCIES
gradle.allprojects{ project ->
project.repositories {
// Remove all repositories not pointing to the enterprise repository url
all { ArtifactRepository repo ->
if (!(repo instanceof MavenArtifactRepository) ||
repo.url.toString() != ENTERPRISE_REPOSITORY_URL) {
if (!repo.url.toString().startsWith("file:")) {
project.logger.lifecycle "Repository ${repo.url} removed. Only $ENTERPRISE_REPOSITORY_URL is allowed"
remove repo
}
}
}
// add the enterprise repository
maven {
name "STANDARD_ENTERPRISE_REPO"
url ENTERPRISE_REPOSITORY_URL
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment