[Nix-dev] Nix for Java Development?

Charles O'Farrell charleso at gmail.com
Sat May 3 08:00:54 CEST 2014


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/20140503/0f887cc0/attachment.html 


More information about the nix-dev mailing list