How to change the order of repositories

Hello,
I load a generic master gradle script in the buildscript block of my application specific build.gradle script. The master gradle configures a set of remote repositories.

Sometimes it is necessary for me to use a snapshot version of a separate library that I want to load from my local maven repository. I don’t want to publish this snapshot version to the remote repo.

If I add mavenLocal() to the repositories block in the master gradle, it works find. If I publish a new snapshot version to my local maven repo, gradle detects the new version and load it if I build my application.

But for me it seems to be nicer to add the mavenLocal() in a repositiories closure inside of my own gradle.buid script instead of the gerenic master gradle. If I do that, then gradle ignores the changed snapshot versions and does not load it any more (maybe it first searches in the remote and if it is there and has not changed, it stops searching in other repos?).

Is there a way to change the repositories order in my build.gradle script or any other generic solution?

Many regards,
Hermann

Is the other library a Maven or Gradle build?

If it’s Gradle, you can use composite builds, which doesn’t require you to rearrange any of your repositories (or publish to Maven local). You can just run with gradle build --include-build ../path/to/other/build.

If the other build is a Maven build, convert it to Gradle :slight_smile:.

You could have an mavenLocal.gradle script like:

gradle.allprojects { project ->
   project.repositories { mavenLocal() }
}

And when you need to put mavenLocal ahead of everything else, you can run with gradle -I mavenLocal.gradle build. The init script will be evaluated first, so your maven local repository will be first.

Hello
thanks for the quick reply. Yes, both are gradle projects.

Your solution approaches are new to me. Sounds very interesting what you write. Thank you very much for that. I’m going to look at them the next few days. Then I’ll report again.

See you
Hermann

No problem.

I mentioned some other resources in this post: