gradlebuild.gradlegradle-plugingradlew

Switch repository based on environment


In my local development environment, I need to use my local repo. But when I build in cloud, I need to use remote repo.

Can someone please help me to achieve this as I'm new to gradle?

EDIT:

This is how I defined Repos. I need to use local repo in local machine and use remote url in Cloud.

repositories {

   maven {
        url 'remote-url'
        credentials {
            username "xyz"
            password = "xyz"
        }
    }   
    
   mavenLocal()
   mavenCentral()
}

Solution

  • I don't know if I get it right but if you mean to have it work locally as offline you can use the gradle command as this on your local machine.

    gradle build --offline
    

    this will only use your local repo and not download anything from the internet.

    Edit: you can pass a variable like this

    ./gradlew build -PuseLocalRepo=true
    

    and use it in the call of the gradle repo like this.

    
     if (project.hasProperty('useLocalRepo') && project.useLocalRepo.toBoolean()) {
        mavenLocal()
    } else {
        mavenCentral()
    }