How to use Google mirror for Maven Central as a direct link to download an artifact/jar?

1.6k Views Asked by At

I am using a shell script to download a number of jar files from maven central repo using direct links (e.g. - this link). I read on a couple of sources that Google hosts a publicly available copy of all the Maven Central artifacts and using it instead of Maven Central provides significant speed up in terms of download speed.

However, to achieve this I could only find out the Maven settings.xml references for using Google mirror (like below):

<settings>
  <mirrors>
    <mirror>
      <id>google-maven-central</id>
      <name>GCS Maven Central mirror Asia Pacific</name>
      <url>https://maven-central-asia.storage-download.googleapis.com/maven2/</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>
</settings>

But this doesn't solve my purpose. I am looking for direct download links to be used in a shell script and not in a maven project. How to do that?

1

There are 1 best solutions below

1
Karttik Mishra On BEST ANSWER

I found the answer to my question. It was easy, you just need to replace the host in the complete URL of the artifact/jar from maven central to google mirror. The structure of the URL looks like:

<HOST><Path to artifact>

Host can assume values of either the maven central repo host or of any mirror for the maven repo.

Example:

  • If downloading from Maven Central, use:

https://repo1.maven.org/maven2/org/openapitools/openapistylevalidator/openapi-style-validator-cli/1.3/openapi-style-validator-cli-1.3-all.jar

  • If downloading from Asia Pacific Google Mirror of Maven Central, use:

https://maven-central-asia.storage-download.googleapis.com/maven2/org/openapitools/openapistylevalidator/openapi-style-validator-cli/1.3/openapi-style-validator-cli-1.3-all.jar

  • If downloading from EU region Google Mirror of Maven Central, use:

https://maven-central-eu.storage-download.googleapis.com/maven2/org/openapitools/openapistylevalidator/openapi-style-validator-cli/1.3/openapi-style-validator-cli-1.3-all.jar

  • If downloading from Americas region Google Mirror of Maven Central, use:

https://maven-central.storage-download.googleapis.com/maven2/org/openapitools/openapistylevalidator/openapi-style-validator-cli/1.3/openapi-style-validator-cli-1.3-all.jar