Reputation: 5780
I want to use new fancy plugin { id: ''}
syntax in Gradle with my custom in-house plugins that are stored in company's Artifacotry. In order to do this I can set maven repository for Gradle Plugin Repostiory in settings.gradle only.
I want to set this globally in my custom Gradle package that would be downloaded using Gradle wrapper. I can define globally dependencies repository and buildscript dependendencies repository in $GRADLE/init.d/repositories.gradle script, but I can not do it for Gradle Plugin Registry because it is required to be placed in settings.gradle.
How can I achieve this?
Upvotes: 4
Views: 1957
Reputation: 639
You can accomplish this using the settingsEvaluated method from the Gradle API.
Put the following in an init script.
def ENTERPRISE_REPOSITORY_URL = "https://repo.gradle.org/gradle/repo"
settingsEvaluated { setting ->
setting.pluginManagement.repositories {
// Remove all repositories not pointing to the enterprise repository url
all { ArtifactRepository repo ->
if (!(repo instanceof MavenArtifactRepository) ||
repo.url.toString() != ENTERPRISE_REPOSITORY_URL) {
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
}
}
}
Upvotes: 2