Skip to content

Instantly share code, notes, and snippets.

@mosabua
Last active January 21, 2020 04:15
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • 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 <manfred@simpligility.com
*/
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
}
}
}
@jcranky
Copy link

jcranky commented Mar 5, 2015

Not working for me, it gets stuck with the forge deps... =(

@jcranky
Copy link

jcranky commented Mar 6, 2015

Great, it is working now. I just had to replace line 26 with

if (repo.name.toString().startsWith("standard-") || repo.name.toString().equals("forge")) {

Otherwise it excludes the forge repo which, as you noted in the code, can't be proxied as of yet. Adding standard- to the dependency is no good because then the script still removes forge from ForgeGradle even though it keeps the project forge repository correct.

@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