Created
January 19, 2017 07:57
-
-
Save liangzai-cool/94b6e33ba946881af69fe4194f541453 to your computer and use it in GitHub Desktop.
Using plugins in init scripts.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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