Override repositories for build task

Hi all, this is my first post!

I want to run a custom version of the “build” task which uses my local Maven repository instead of Maven Central/my custom Nexus repository in IntelliJ, as I am developing both the project as well as an in-progress version of a library that uses it, and I would like to only use that version and ignore what is going on in Nexus/Maven Central.

Of course, I can just replace the repository{} section with mavenLocal() and just hope I don’t commit it down the line, but I was hoping there is a cleaner solution, like somehow I can “override” the repository{} section via a command line argument. This also requires me to clean out my caches. I’d rather not explicitly declare mavenLocal() and not have to clean out my caches either. Is this possible?

I’d also be happy if I can define a custom task which does a build with different repositories, but I can’t quite work that one out.

Are they both Gradle projects, or is the library maven?
If both Gradle then consider using composite builds instead. For example, to build your application with your local library:

cd app/dir
./gradlew --include-build path/to/library build

If the library project is maven you can conditionally include the local maven repository by modifying the application’s build like:

repositories {
    // put before other repos to prioritize it
    if( hasProperty( 'mavenLocal' ) ) {
        mavenLocal()
    }
    // your other/Nexus repos
}

Then run your build like:

./gradlew -PmavenLocal build
1 Like

Thanks, both of those solutions seem good!
It’s primarily a Gradle library for a Gradle application, though I do have some Maven ones as well, so I’m guessing mixing and matching both solutions should work fairly well.