Switch between multiple repositories when building


(Eddie) #1

Hi,

I have multiple repositories, the connections of them are not stable. The build will stop when the first repo’s connection is timeout, and it won’t try the second one.

How could i do to let it try another one when the connection timeout?

Thanks.


(Eddie) #2

Can anyone help me please.

Is it possible?


(Dimitar Dimitrov) #3

Please provide an example build illustrating your issue.


(Eddie) #4

Thank you for your reply.

and this is part of my setting

buildscript {
  repositories {
    jcenter()
  }
  repositories {
      maven { url "http://172.21.0.21:8081" }
  }
  dependencies {
      classpath "org.springframework.boot:spring-boot-gradle-plugin:1.5.1.RELEASE"
  }
}

And when i do

gradle clean build

It goes wrong like this, and won’t try the other one.

Could not resolve all dependencies for configuration ‘:classpath’.
Could not download spring-boot-gradle-plugin.jar (org.springframework.boot:spring-boot-gradle-plugin:1.5.1.RELEASE)
Could not get resource ‘https://jcenter.bintray.com/org/springframework/boot/spring-boot-gradle-plugin/1.5.1.RELEASE/spring-boot-gradle-plugin-1.5.1.RELEASE.jar’.
Could not HEAD ‘https://jcenter.bintray.com/org/springframework/boot/spring-boot-gradle-plugin/1.5.1.RELEASE/spring-boot-gradle-plugin-1.5.1.RELEASE.jar’.
Connect to jcenter.bintray.com:443 [jcenter.bintray.com/75.126.118.188] failed: Connection timed out (Connection timed out)


(Eddie) #5

Did i make sth wrong or it’s not clear?

Thanks.


(Dimitar Dimitrov) #6

Why is that repo unreachable? Different reasons would prompt different solutions.

If I am to guess, you need to use different repository in different environments. This is typically solved by externalizing the repo configuration (either the URL in your ~/gradle.properties or the whole repo configuration in your ~/init.gradle)

Again, depending on your scenario there can be different ways to approach it, including hacks like adding a hook in your build that would ping al configured repos and disable/remove the ones that don’t respond.


(Eddie) #7

Thank you for your time.

You’re right, i’m trying to use different repository in different environments, i will do some search about what you said.
BTW i really am a beginner here, so thanks for your patient.


(Dimitar Dimitrov) #8

If you are using a laptop, and moving it around, so you need to use different repos from different locations, I would suggest to implement switching logic based on the localhost IP subnet or hostname (keep in mind that hostname takes a bit to resolve and it will be done during each build).

If you have the same codebase checked out from different machines and each machine needs different repo, then it will be simpler to specify the repo URL in ~/.gradle/gradle.properties and make sure that each machine is set up to point to the right repo. This requires a one-time extra step, but gives you the flexibility to onboard new locations without touching the build.

Finally, using ~/.gradle/init.gradle you may completely rewrite whatever repos the build.gradle file specified (hint: the repositories domain object is a collection, mutable during hte config phase). The management aspect is similar to the ~/.gradle/gradle.properties solution, but it allows you to run any external build without modification.


(Eddie) #9

Thanks, ddimitrov, I’ve solved the problem.

Like you said i just specify the repo URL in gradle.properties, as i’m a beginner, it literally took me a lot of time to configure the gradle.properties and other relevant settings.

Thank you so much for your help.