Skip to content

Instantly share code, notes, and snippets.

@xshyamx
Created January 22, 2018 05:17
Show Gist options
  • Save xshyamx/9d71806b958aad109198f3587e06f46f to your computer and use it in GitHub Desktop.
Save xshyamx/9d71806b958aad109198f3587e06f46f to your computer and use it in GitHub Desktop.
Shell script to generate a maven pom.xml from a list of jars
#!/bin/sh
lib_dir="$1"
if [ "$lib_dir" == "" ]; then
echo Please specifiy the directory for the jars
exit 1
fi
cat <<EOF | tee pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>group-id</groupId>
<artifactId>artifact-id</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
EOF
for f in $lib_dir/*.jar; do
sha=$(shasum -b $f | awk '{print $1}')
url="http://search.maven.org/solrsearch/select?q=1:%22${sha}%22&rows=20&wt=json"
if curl -s -o json -L $url; then
gid=$(jq -r '.response.docs[0].g' json)
aid=$(jq -r '.response.docs[0].a' json)
ver=$(jq -r '.response.docs[0].v' json)
#echo $gid, $aid, $ver
cat <<EOF | tee -a pom.xml
<dependency>
<groupId>${gid}</groupId>
<artifactId>${aid}</artifactId>
<version>${ver}</version>
</dependency>
EOF
rm -f json
fi
done
cat <<EOF | tee -a pom.xml
</dependencies>
</project>
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment