-
-
Notifications
You must be signed in to change notification settings - Fork 14.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Java packages #20444
Java packages #20444
Conversation
@NeQuissimus, thanks for your PR! By analyzing the history of the files in this pull request, we identified @edolstra, @cmfwyp and @civodul to be potential reviewers. |
/cc @copumpkin @shlevy @puffnfresh @bendlas @Mathnerd314 because they all had comments on the old PR |
commonsLoggingApi_1_1 | ||
findbugsJsr305_2_0_1 | ||
googleCollections_1_0 | ||
junit_3_8_1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
junit_3_8_1
+ junit_3_8_2
- isn't that duplicate classes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At runtime, yes... But they are both required as transitive dependencies...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strange, things like this could leads to https://en.wikipedia.org/wiki/Java_Classloader#JAR_hell and there are tools to work with it, like http://docs.jboss.org/tattletale/userguide/1.1/html/reports.html#multiplejarfiles
But it could be more an issue for maven itself than this derivation.
How did you generate the list of dependencies?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed my local ~/.m2
built the project using the "normal" way and then did a find ~/.m2/repository -name '*.jar' -o -name '*.pom'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO maven
shouldn't use junit
at runtime at all. On a first glance it could be test dependency
of https://mvnrepository.com/artifact/org.apache.maven.surefire/maven-surefire-common/2.17
Anyway, it's ok if it doesn't break it.
We could try to optimize it later. It may be worth to dig into mvn dependency:tree
and treat compile
, test
, provided
scopes differently instead of listing ~/.m2
tree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, you could strip certain dependencies if you choose to skip tests. However, that did not seem worth the effort right now. Most builds from source should want to not skip tests :)
Just an idea. It would be nice if
instead of:
|
Re: groupId/artifactId YES! |
Ping :) |
restarted travis builds |
looks like travis fails |
sorry i just notices, that this PR is meant for feedback. ignore me |
👍 |
I say we merge it and iteratively improve on it. It fills in a big gap in nixpkgs today, and isn't going to hurt/conflict with any of the other package ecosystems by being merged. |
The travis failures definitely look valid. |
I will take a look at this today or tomorrow (I hope). Seems that Maven Central is sensitive to the (unintentional) double slash all the sudden... |
91c5907
to
8a7a44c
Compare
Found two typos, everything should be good to go now. Let's see what Travis thinks... |
There we go, Travis is happy |
One more question: do people always just ask for the pom and jar combination or are there use cases for only asking for one? I'm wondering if we could cut down on the hash noise a bit by making |
For example, I have a (yet unpushed, sorry) |
I found it actually depends on the artifact... Some are POM-only, most want JAR and POM but it is technically allowed to only use the JAR and leave the POM alone (i.e. if you want to avoid pulling transitive dependencies). By doing it this way, I just decided to give all the options :) |
@NeQuissimus I guess I'm saying that you could still allow people to ask for all those combinations without requiring one hash per thing you ask for. It might not be worth it, but as a potentially avid user of this thing I'm a little concerned about the code's UX 😄 |
I am hoping to eventually have some sort of auto-generation. I mean, for now if you want to build your own Maven project, you will probably need to do so much by hand, it is going to get cumbersome real quick. This is essentially more of a PoC than anything, I suppose :) |
How's this going? |
This is done from my POV |
Fine by me! |
@@ -9761,6 +9761,10 @@ in | |||
|
|||
leaps = callPackage ../development/tools/leaps { }; | |||
|
|||
### DEVELOPMENT / JAVA MODULES | |||
|
|||
javaPackages = recurseIntoAttrs (callPackage ./java-packages.nix { }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually think this should be callPackages
rather than callPackage
. The difference is that the former recurses (one level) into the inner attrset and makes the individual derivations there overridable. I think you'll find that in the current setup, override[Derivation]
won't work on anything inside there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's going to mess with my lists. Is there a straight-forward List -> Set
function?
callPackages
wants things to be sets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I don't see the lists you're speaking of. Can you point them out? It looks like java-pacakges.nix
results in a big attrset full of attributes it inherits from other .nix files?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I get
~/dev/nixpkgs java_packages ✗
▶ nix-build -A javaPackages.mavenHello_1_1 --show-trace
error: while evaluating the attribute ‘buildPhase’ of the derivation ‘maven-hello-1.1’ at /home/nequi/dev/nixpkgs/pkgs/development/java-modules/build-maven-package.nix:10:10:
while evaluating ‘optionalString’ at /home/nequi/dev/nixpkgs/lib/strings.nix:138:26, called from /home/nequi/dev/nixpkgs/pkgs/development/java-modules/build-maven-package.nix:24:7:
while evaluating ‘unique’ at /home/nequi/dev/nixpkgs/lib/lists.nix:432:12, called from /home/nequi/dev/nixpkgs/pkgs/development/java-modules/build-maven-package.nix:12:14:
while evaluating ‘flatten’ at /home/nequi/dev/nixpkgs/lib/lists.nix:90:13, called from /home/nequi/dev/nixpkgs/pkgs/development/java-modules/build-maven-package.nix:12:22:
while evaluating the attribute ‘mavenMinimal’ at /home/nequi/dev/nixpkgs/pkgs/development/java-modules/maven-minimal.nix:13:3:
while evaluating ‘flatten’ at /home/nequi/dev/nixpkgs/lib/lists.nix:90:13, called from /home/nequi/dev/nixpkgs/pkgs/development/java-modules/maven-minimal.nix:13:18:
while evaluating ‘concatMap’ at /home/nequi/dev/nixpkgs/lib/lists.nix:79:18, called from /home/nequi/dev/nixpkgs/lib/lists.nix:92:10:
while evaluating anonymous function at /home/nequi/dev/nixpkgs/lib/lists.nix:92:21, called from undefined position:
while evaluating ‘flatten’ at /home/nequi/dev/nixpkgs/lib/lists.nix:90:13, called from /home/nequi/dev/nixpkgs/lib/lists.nix:92:24:
while evaluating ‘mkAttrOverridable’ at /home/nequi/dev/nixpkgs/lib/customisation.nix:111:33, called from /home/nequi/dev/nixpkgs/lib/attrsets.nix:199:52:
value is a list while a set was expected
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In maven-minimal I build up a long list of default dependencies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also genAttrs
if you want to specify a function to create attribute names
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to open up all kinds of weird little things. I won't get around to doing this in the near future... I had hoped to get this into the next release, but I will try to fix this first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dang :\ maybe try to break it up into smaller, mergable chunks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or merge it now as is, and then work on fixing it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pretty much the bare minimum to build anything with Maven :) If we can deal with callPackage
instead of callPackages
, let's merge...
Sure, fine by me. Thanks for the effort and patience! |
Don't forget to make an issue in the issue tracker btw! |
@NeQuissimus I'm trying to package an Ant-based project right now that needs a couple of JARs not shipped inside the tarball from Maven Central. Could you please give an example on how to add a Java package to the build inputs and modify the classpath? |
You're going to need to write something similar to |
looks like no one got round to doing all those improvements and fixes in the end, huh? 🙂 I'm currently wondering about wether to build an existing maven based project with nix. I'm fairly new to writing my own derivations and it's been quite a while since I've used java and I've also never really got to know the build systems in the java ecosystem, mostly I relied on my IDE doing the work for me back then. |
Note: I am replacing #12770 with this.
I have taken most of the concepts from the mentioned PR and cleaned them up.
I have also added a full build of JUnit 4.12 and a sample project, which uses said JUnit version.
Most artifacts are binaries because an extremely simplistic project like the one I created requires hundreds of artifacts. Building all of those from source is (surprisingly) impossible. - The Java world for you :D
I am terrible at rebasing in git, so I suggest we squash upon PR merge. (I did things out of order and in weird chunks, so it would not be a straight rebase with squashing; unless we remove context)
Here is what I have done:
Build support
Essentially what was already in #12770 except much less copying because as it turns out, Maven does like symbolic links if you do it right :)
I have a way to fetch Maven Central binaries (
fetchMaven
) and a build helper (mavenbuild
).I have also added optional
skipTests
andquiet
parameters (both of which default totrue
).Why default
skipTests
totrue
?Turns out, JUnit expects
hamcrest-core
on the classpath without defining it as an explicit runtime dependency. If somebody knows how to convince apom.xml
that depends on JUnit but nothamcrest-core
to run tests in offline mode, please do provide feedback.Plugins
I have added a large number of default Maven plugins.
Theses are needed to get Maven to do anything at all...
I have created
mavenMinimal
for this purpose, a list of plugins and their dependencies that are required no matter what you are building. This list of automatically included when usingmavenbuild
.Libraries
So far, I have all the libraries that are needed to
Mirror
I have added a
maven
alias to thefetchurl
mirrors. This is not strictly required but may help in the future if URLs change or another mirror can be added.Useful stuff
Collections
Generally, if you have one of the Maven libraries that you depend on, they eventually pull in all their brothers and sisters with the same versions numbers as well. So I created
mavenLibs
collections to make things easier.SHA512
Sorry @copumpkin, I know we just talked about it but the number of SHA512 in my branch had already been in the triple digits, so I kept it this way. (Forgive me :D)
Maven
The Maven/Java environment is dirty, crazy and unorganized for the most part.
Try building a "Hello World" application and you need to pull in hundreds of dependencies.
Don't even think about building all of those from source (see #12770) for examples of circular dependencies and seemingly endless chains of dependencies that will feel like time travel into the beginnings of Java.
This is why the code in this PR looks the way it does and lists more than 3,500 new LoC.
Compared to the old PR I have already abstracted and massively simplified...
Future
I would ask for any feedback I can get here.
This has been a lot of work but if most people are against this, I won't be mad.
If we decide to include
javaPackages
into nixpkgs, we should definitely write some documentation, which is why I added the appropriate label.Note sure what else to say...