[Nix-dev] Nix for Java Development?

Sander van der Burg - EWI S.vanderBurg at tudelft.nl
Mon May 5 13:13:37 CEST 2014


Hi,

Interesting blog post that reminds me of some stuff I was working on years ago.

In one of my research case studies, I actually had to build a Maven project in Nix to also make it deployable with Disnix. Since Maven and Nix don't really work well with each other (because Maven does dependency management in addition to build management), I had to invent some other strategy to make the project buildable.

What I did is crafting my own function abstractions that build Java artifacts, e.g. JAR files, WAR files etc from Eclipse projects. I manually ported all the sub projects of my case studies to my own function abstractions and that seemed to work quite well.

Since every build artifact is built purely through a Nix function, we can also utilise Nix's transparant source/binary deployment model for Java artifacts, which means that if you want to build something that has been built elsewhere, we can download these packages instead of building them ourselves.

Unfortunately, I never publicly released my function abstractions, but they might still be useful.

Maybe, I could dig them up, release them and see if I can make them work again with some meaningful example.

More information on these functions can be found in our SEAA 2010 paper:

http://www.st.ewi.tudelft.nl/~sander/pdf/publications/vanderburg10-automateddeployment.pdf

As well as the corresponding chapter 4 in my PhD thesis:

http://www.st.ewi.tudelft.nl/~sander/index.php/phdthesis

________________________________
From: nix-dev-bounces at lists.science.uu.nl [nix-dev-bounces at lists.science.uu.nl] on behalf of Charles O'Farrell [charleso at gmail.com]
Sent: Saturday, May 03, 2014 8:00 AM
To: nix-dev at lists.science.uu.nl
Subject: [Nix-dev] Nix for Java Development?

Hi all,

So I apologise in advance for the long and winding email.

I've been thinking for a while now about how the current state of builds, specifically in the Java world in which I currently reside. I've recently been inspired by Lex Spoon's post about Maven, which match up with my own thoughts, and led me to Nix.

http://blog.lexspoon.org/2012/12/recursive-maven-considered-harmful.html

So I've started kicking the tires of Nix to see how far I can take it as an experiment for building Java projects. I'm not expecting everything to work, but I want to get a feel for how far I can run with it.

I was talking to Shea the other day about recursive builds, which I think is one area that may need tweaking.

http://nixos.org/irc/logs/log.20140427

I suspect my first question probably should have been the following. I have something like:

Project A -> (git sha1) -> Project B

Where the dependency is declared as a Git dependency (see my discussion with Shea above). If we ignore recursive builds for a second and just assume we're using Git submodules and everything has been fetched already. When a developer first clones Project A and tries to build it should possibly try to download the compiled jar from Hydra (and all it's binary dependencies too). However, from my investigations the derivation is obviously going to contain dependencies to platform specific versions of a whole bunch of stuff (which isn't surprising).

In the Java world you really only care about the Java compiler version. Any platform/version of Java 5 will produce compatible bytecode. Arguably there isn't a need to re-build the source unless the _major_ version of the compiler has been changed. And in fact you can even depend on bytecode compiled by older Java versions (but not newer). Java dependency managers don't even bother taking the Java version into account, and it "mostly" works, but there's no guarantee.

To (finally) get to my question. Could Nix be made to support this style of building? Can you declare a dependency on "Java 5" and have that download binary jars or whatever version of the compiler it needs _but_ without requiring a complete rebuild of everything if that changes slightly. Would I be abusing Nix beyond recognition (I suspect I would be)? I think Nix really does a great job of source/binary builds; nothing else comes anywhere close. I'm not sure what my alternatives are.*

The other thing that I've considered is that building from source may not actually be necessarily slower than downloading the binary files, and maybe my brain has been corrupted by many years of Maven and binary-only dependencies. Although if we're talking Scala you might find that not to be the case, it can be _significantly_ slower to compile than Java. Also a full rebuild of _everything_ because of a minor version bump in Java does seem excessive (what happens if you depend on 100 sub projects, all using Nix).

I'm happy to jump on IRC if that makes this question easier to answer. I appreciate any help/advice/heckling people are willing to give. :)

Charles O'Farrell

* FWIW Language-specific dependency tools, while convenient, seem wrong to me, and I think we can do better. I'm hoping that Nix, or something like it, could eventually be the basis for a Java-aware build/dependency DSL.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.science.uu.nl/pipermail/nix-dev/attachments/20140505/7db68510/attachment-0001.html 


More information about the nix-dev mailing list