Help packaging a Java app?

I’d like to package Rachota, a timetracking app. I see that it’s designed to be built with Maven, but I don’t know the first thing about that tool (or Java development in general). I also see that there are no Nixpkgs docs about using maven, and that there are a two(?) functions for building maven projects in nixpkgs code base. One of them requires a secondary tool, mvn2nix. It is not immediately clear to me how to use any of these tools, and there aren’t any examples to crib off of in the nixpkgs repo.

Could someone point me to examples of Maven-built packages that would be good to copy from? Or give me pointers of any sort? :slight_smile:

Thanks!

If the app has little number of dependencies to download, you can model your code after processing (https://github.com/NixOS/nixpkgs/blob/9541c6b7bf0c2ce78633fd27498121ef28975881/pkgs/applications/graphics/processing/default.nix) (it uses ant but there is no big difference, just replace ant build with mvn package)

If there is a lot of jars to download from maven cental, then it is a problem which has many solutions. none of them is perfect.

  1. Maven can be run twice, the first time to download all dependencies into fixed-output derivation and the second for the offline build (example https://github.com/NixOS/nixpkgs/blob/44aca430c3745c8a5de75afc7b170f5dc0e21bd0/pkgs/applications/science/misc/gephi/default.nix). Disadvantage: outputHash of the FOD is drifting with time and will need to be updated in few months (because maven dependencies can refer to “latest” vesrion of some artifact, and when the artifact is updated, the output of the phase is changed)
  2. Make a big list of all dependencies (example https://github.com/NixOS/nixpkgs/blob/d80de1b135cf098d8acd134385400fe3956a59e5/pkgs/development/compilers/graalvm/default.nix#L64-L69). Disadvantage: difficult to maintain and update. This is where tools like mvn2nix are suppose to help.
  3. Mixes of the two approaches above (example: https://github.com/NixOS/nixpkgs/tree/92a047a6c4d46a222e9c323ea85882d0a7a13af8/pkgs/applications/networking/cluster/chronos)

As I wrote in Shell.nix or default.nix for java project I have used Mavenix for some projects at work and was quite happy with the experience. Mavenix creates a lock file and a Nix expression. The latter can be modified, however, one needs to be careful because it may break the script that is used to update the lock file. There were some issues but together with the maintainer of Mavenix those were resolved quite quickly. Unfortunately I do not have any public projects to share.

3 Likes

This github issue documents the problem somewhat, and discusses some alternatives:

Thanks for the tips, folks! I’ll let you know how it goes.