Fetch Maven Central info from the Command Line

Fetch Maven Central info from the Command Line

Fetch Maven Central info from the Command Line

Fetch Maven Central info from the Command Line

Mar 23, 2021

Mar 23, 2021

Mar 23, 2021

×

×

×

Dev

Dev

Dev

Sometimes we need to fetch some Maven central information from the command line. Like, latest version, all recent versions for a particular artifact, and so on. This is particularly useful for automated builds and various reports.

We were not aware of this, and actually got positively surprised, but Maven Central (more specifically search.maven.org) provides a good range of APIs to search things in their servers. 😮 After all, I think it's time to stop blaming Sonatype OSS and its ecosystem for good now… 🙈

We will use neow3j project as an example in this article. 🤔

Also, make sure you have curl and jq command-line tools installed. We will use some magic with jq, which is very useful to parse JSON in the shell.

Get the latest version of the io.neow3j:core artifact:

curl -s http://search.maven.org/solrsearch/select\?q\=g:"io.neow3j"+AND+a:"core" \
    | jq -r '.response .docs[0] .latestVersion'

List the last 10 versions of io.neow3j:core artifact:

curl -s http://search.maven.org/solrsearch/select\?q\=g:"io.neow3j"+AND+a:"core"\&rows\=10\&core\=gav \
    | jq -r '.response .docs | .[] | .v'

List the last 10 artifact identifiers where it contains the class io.neow3j.compiler.Compiler in the group io.neow3j:


curl -s http://search.maven.org/solrsearch/select\?q\=g:"io.neow3j"+AND+fc:"io.neow3j.compiler.Compiler"\&rows\=10\&core\=gav \
    | jq

curl -s http://search.maven.org/solrsearch/select\?q\=g:"io.neow3j"+AND+fc:"io.neow3j.compiler.Compiler"\&rows\=10\&core\=gav \
    | jq -r '.response .docs | .[] | .id'

There are many other things it's possible to do and to query. You can explore by yourself by reading their docs. 🙏

I was thinking a bit…. and a next step would be to turn this into a small Javascript library. 🚀 🤔

…but that's something for another article. 😅 😆

© Made with

♥️

in 🇨🇭 Switzerland

© Made with

♥️

in 🇨🇭 Switzerland

© Made with

♥️

in 🇨🇭 Switzerland

© Made with

♥️

in 🇨🇭 Switzerland