Skip to content

Instantly share code, notes, and snippets.

@mosabua
Last active January 21, 2020 04:15
Show Gist options
  • Save mosabua/cd0d5a4ddac550273157 to your computer and use it in GitHub Desktop.
Save mosabua/cd0d5a4ddac550273157 to your computer and use it in GitHub Desktop.
init.gradle file for proxying all repositories with Sonatype Nexus
/**
* init.gradle file for development using Nexus as proxy repository
*
* @author Manfred Moser <[email protected]
*/
apply plugin:NexusRepositoryPlugin
class NexusRepositoryPlugin implements Plugin<Gradle> {
final static String LOG_PREFIX = "init.gradle/NexusRepositoryPlugin:"
final Closure NexusConfig = {
maven {
name = 'standard-nexus'
url = 'http://localhost:8081/nexus/content/groups/public'
}
// if required you can add further repositories or groups here and they will
// be left intact if the name starts with standard-
// although it is better to just add those repositories in Nexus
// and expose them via the public group
}
final Closure RepoHandler = {
all { ArtifactRepository repo ->
if (repo.name.toString().startsWith("standard-") ) {
println "$LOG_PREFIX $repo.name at $repo.url activated as repository."
} else {
if (repo instanceof MavenArtifactRepository) {
remove repo
println "$LOG_PREFIX $repo.name at $repo.url removed."
} else {
println "$LOG_PREFIX $repo.name kept (not a Maven repository)."
}
}
}
}
void apply(Gradle gradle) {
// Override all project specified Maven repos with standard defined in here
gradle.allprojects{ project ->
println "$LOG_PREFIX Reconfiguring repositories and buildscript repositories."
project.repositories RepoHandler
project.buildscript.repositories RepoHandler
// The minecraftforge repo has problems being proxied so we need to leave it in place directly.
project.repositories NexusConfig
project.buildscript.repositories NexusConfig
}
}
}
@JLipp
Copy link

JLipp commented Jul 16, 2015

Great, this is exactly what I was looking for, thanks!

To also be able to build Android Studio project with gradlew, I added the following lines to keep the local support repos replacing line 30/31:

if (!repo.url.toString().startsWith("http") &&
  repo.url.toString().contains("Android") ) {
  println "$LOG_PREFIX    $repo.name at $repo.url kept because local Android extras repo."
} else {
  remove repo
  println "$LOG_PREFIX    $repo.name at $repo.url removed."
}

@betko
Copy link

betko commented Oct 26, 2018

Thank you very much. This is working for me. You save my day 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment