Help packaging a Java application

I am trying to use mavenix and am running into problems being that my “app” needs Java 17 and mavenix is stuck on 8.

I think the solution is to rebuild the package using 17, but I don’t really know how to do this.


1 Like

@fzakaria ?? :wink:

I haven’t used mavenix before but ideally you should be able to override any of the functions to provide your own Java for Maven or JDK – perhaps with an overlay for

1 Like

I haven’t used mavenix yet - the maven.buildMavenPackage from nixpkgs was sufficient for my needs so far - might be worth a try?

1 Like

First, use mvn2nix, and if that doesn’t work in the end, use maven.buildMavenPackage.

I haven’t used mvn2nix, because I saw Nixpkgs 23.11 manual | Nix & NixOS mentioned it is ‘no longer recommended’ - it’d be interesting to learn why you still prefer it?

1 Like

Ah, I see. I wasn’t aware of that. I found that within mvn2nix, even if it might fail, I could specify more fine-grained build options compared to maven.buildMavenPackage. However, I recently managed to solve a Spring Boot issue using buildMavenPackage. I learned about this by, of course, taking a look at the nixpkgs code. Isn’t buildMavenPackage also built using mvn2nix? So, I practice with mvn2nix, and if I run into issues with the maven repo, I switch to using buildMavenPackage. I mentioned that mvn2nix allows for more option adjustments, but buildMavenPackage also allows for option adjustments. So I recommend trying to build basic ‘hello world’ code with mvn2nix first, and if that doesn’t work, then using buildMavenPackage.

Obviously, what’s above is not necessarily more accurate than the official manual; it’s just my thoughts based on personal experience. Also, personally, I wish gradle2nix could somehow be revived.

Sigh… Neither of them works with spring-boot again. Maybe someday, huh?

After clearing the cache with ‘sudo rm -rf /nix/store/.links’, the installation works well again… Probably there was an issue with the auto garbage collection, which seems to have prevented fetching the maven temp properly.

Could you create an issue with example code, a derivation and the steps to reproduce the problem? Or share them here?

1 Like


sb-example = let
JDK = graalvm17-ce;
(if stdenv.isLinux then (stdenv.mkDerivation rec {
version = “0.0.1”;

NAME = "${pname}-${version}";

src = ./.;    
groupId = "org.plumpmath";
className = "Sb";    
buildInputs = [ maven ];
nativeBuildInputs = [ JDK makeWrapper ];
dontFixup = true;
buildPhase =

    mvn -X -Dmaven.repo.local=$out clean install spring-boot:repackage    
  installPhase = ''
    mkdir -p $out/bin
    cp target/${NAME}.jar $out/
    makeWrapper ${JDK}/bin/java $out/bin/spring-${pname} \
    --add-flags "-jar $out/${NAME}.jar"

}) else (maven.buildMavenPackage rec {
version = “0.0.1”;
NAME = “${pname}-${version}”;
src = ./.;
mvnHash = “sha256-cKYXx1DER6Kqph8yyq5ZNqGnwMZZc8cryH852lXL9jg=”;
nativeBuildInputs = [ makeWrapper ];
installPhase = ‘’
mkdir -p $out/bin
cp target/${NAME}.jar $out/${pname}.jar
makeWrapper ${JDK}/bin/java $out/bin/spring-${pname}
–add-flags “-jar $out/${NAME}.jar”



Do you also have the code to go with this packaging? :innocent:

I understand if you can’t share the code for your ‘actual’ project - does a minimal spring-boot project already show the problem?

1 Like

I had this:

(Please disregard the code :wink: )

I didn’t try buildMavenPackage wiht it yet, I’ll do it soon.

1 Like

I understand your fishing and open mind -.,- My problem is a different problem. That code works fine.

I just hope that in the nix ecosystem, a way to package both spring-boot and gradle Java projects made with gradle, as well as clojure/scala etc projects, and unify the jvm project can be completed. Our goals are the same.