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 | |
} | |
} | |
} |
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."
}
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
Great, it is working now. I just had to replace line 26 with
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.