Last active
January 21, 2020 04:15
-
-
Save mosabua/cd0d5a4ddac550273157 to your computer and use it in GitHub Desktop.
init.gradle file for proxying all repositories with Sonatype Nexus
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
/** | |
* 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 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you very much. This is working for me. You save my day 😄