Skip to content

Instantly share code, notes, and snippets.

@arichiardi
Created June 3, 2019 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arichiardi/d7542941be959f06e2d420d3bc12a5b1 to your computer and use it in GitHub Desktop.
Save arichiardi/d7542941be959f06e2d420d3bc12a5b1 to your computer and use it in GitHub Desktop.
Convert the output of mvn dependency:list to leiningen deps
#!/usr/bin/env bash
set -euo pipefail
# The following is the mvn dependency:list expected output
#
# [INFO] The following files have been resolved:
# [INFO] com.elasticpath.service.tenant:tenant-service-model:jar:1.0-SNAPSHOT:compile
# [INFO] com.elasticpath.service.tenant:tenant-service-dao:jar:1.0-SNAPSHOT:compile
# We need to get rid of some cruft first, like [INFO]. Note that we also need
# to start consuming line that have more than one whitespace after [INFO].
# Handling both stdin and file with the while loop
# https://stackoverflow.com/questions/6980090/how-to-read-from-a-file-or-stdin-in-bash
while IFS= read -r line; do
printf '%s\n' "$line" | \
sed -n -e 's/^\[.*\]\s\{2,\}\(.*\)/\1/p' | \
awk -F: '{ print "["$1"/"$2 " \"" $4"\"]" }'
done < "${1:-/dev/stdin}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment