Search maven from the commandline using httpie and jq
Sometimes I like to know what the latest version of a library in maven central is. As I don’t like to always open a browser tab for search but almost always have a terminal window at hand, I just wrote s small script that uses httpie and jq to get the information I want (that’s all one line in the script):
#!/usr/bin/env sh http search.maven.org/solrsearch/select rows==10000 q=="$1" | jq '.response.docs | .timestamp |= (. / 1000 | todate) | (.timestamp)+" "+(.id)+":"+(.latestVersion)' | tr -d '"' | sort -k2
The script retrieves the searched values from search.maven.com, setting the limit to 1000, the default is 10. Then it uses jq to parse the returned JSON. The timestamp field is formatted to a readable format and then is printed along with the maven id and the latest version number. The quotes are removed from the output and it is sorted by the artifact id.
I saved this script as
smvn and made it executable.
A sample run:
$ smvn "springframework elasticsearch" 2020-09-17T14:37:19Z org.springframework.boot:spring-boot-starter-data-elasticsearch:2.3.4.RELEASE 2020-09-16T10:10:50Z org.springframework.data:spring-data-elasticsearch:4.0.4.RELEASE