mavenmaven-mirroring

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


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?


Solution

  • 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:

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

    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

    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

    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