Determining Maven dependencies via hashes

In my last post, I described the manual process of determining the dependencies of jar files. Always the one for automation, I decided to write a little helper tool:

maven-dependency-helper

This tool allows you to output dependency tags for single jars or jars located in directories.

The following example queries Maven Central for a single jar.

java -jar maven-dependency-helper-0.0.1-spring-boot.jar \
  --jar /some/where/5.3/iscwt-5.3.jar

Which results in the following output:

<dependency>
  <groupId>de.intarsys.opensource</groupId>
  <artifactId>iscwt</artifactId>
  <version>5.3</version>
</dependency>

For processing all jars in a directory, but skip ones that contain -sources or -javdadoc you can use something like this:

java -jar maven-dependency-helper-0.0.1-spring-boot.jar \
  --dir /some/dir/ \
  --exclude ".*(-sources|-javadoc).*"

Which will generate output like this:

<dependency>
  <groupId>de.intarsys.opensource</groupId>
  <artifactId>iscwt</artifactId>
  <version>5.3</version>
</dependency>
<dependency>
  <groupId>de.intarsys.opensource</groupId>
  <artifactId>isfreetype</artifactId>
  <version>5.3</version>
</dependency>

Automation is so much nicer. 🙂