Get the latest artifact version from Maven Central via shell command

If you need to retrieve the latest version of an artifact on Maven Central you can use the following shell command (example for groupId=org.apache.maven.plugins and artifactId=maven-compiler-plugin):

> curl -s http://search.maven.org/solrsearch/select?q=g:"org.apache.maven.plugins"+AND+a:"maven-compiler-plugin" |grep -Po 'latestVersion.:.\K[^"]*'
> 3.8.0

This will query the search API on search.maven.org for the given groupId and artifactId coordinates. The result from search.maven.org is in JSON format. We are only interested in the value of the ‘latestVersion‘ attribute, which is extracted with grep.

The ‘-s‘ option is for ‘Silent Mode’ to suppress download stats messages from curl and really only print the result from grep. Note that this option is not available on all systems (e.g. macOS).

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s