This program will find the Maven coordinates for all the Java archive (e.g., jar) files in a specified directory.
I inherited a Java program that was packaged using a custom build utility. I wanted to move it over to Maven or Gradle, so I could automate the build using a tool like Jenkins or Travis CI.
This program had over 200 libraries it used, and I did not want to search Maven Central manually for all of these libraries.
That's when I found make-pom. While
I really loved make-pom
, I ran into some challenges getting it set up on
my laptop. That, and I didn't like the fact that it required Bourne shell,
Python 2, and a few other external binaries like sha1sum
.
I decided to write a program that did much the same thing, but entirely in Java. I also introduced caching, external configuration, logging, output options, and multiple Maven repository searching.
- Look for each Java archive (e.g., .jar) file in a specified directory.
- Calculate the hash value for the given file.
- Determine if we already have the Maven coordinates for this file.
- If not, see if the file includes a pom.properties file.
- If not, search Maven Central for the given hash value.
- Store the Maven coordinates in an internal database for future reference.
- Output the Maven coordinates as requested (e.g., POM, JSON, not at all).
See find-dependency.json
. This program
will look for this file in the class path.
$ java -jar find-dependency-1.0.jar -d /path/to/archives [-o fn [-f fmt]]
Option | Description | Default |
---|---|---|
-d dir, --directory dir | The directory to look for Java archive files. | None. This option is required. |
-f fmt, --format fmt | The output file format. One of JSON or POM . Only valid when used with -o or --output . |
JSON |
-o fn, --output fn | The output file. | None. If not specified, nothing is output, just loaded in the database. |
This program makes use of features that require Java 11 or newer (e.g., HTTP Client).
This program also makes use of the following external libraries:
This program uses H2 as a database to cache results. You can easily use a different
database by changing the driver, connection string, and SQL statements in
find-dependency.json
.
- Better results handling when searching multiple Maven repositories.
This program was heavily-inspired by make-pom. Thanks, @sjbotha!