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
documentation: add documentation for buildMaven #100660
documentation: add documentation for buildMaven #100660
Conversation
c439d08
to
ee91f64
Compare
ee91f64
to
ffbb3a8
Compare
ffbb3a8
to
b424e0a
Compare
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.
A few comments:
-
Double invocation
- You mention twice that subsequent runs my result in different output hashes. If our situation is so awful, putting it in the docs is a kind of "recommendation" to keep using this method, so perhaps it'll be better not to document this?
- Why do you use
src = ./.
;? I thought this is a guide that teaches people how to contribute java packages to Nixpkgs.
-
buildMaven
- It should be made clear that a Nixpkgs contributor needs to download the project's source code, and run
mvn org...
in the project's root directory, or where ever the mvn entry point file (pom.xml
?) is. - You kind of mix the "build" sections.
- It should be made clear that a Nixpkgs contributor needs to download the project's source code, and run
-
General
- I'd start this document by writing that the derivation one would
callPackage
to should look like the derivation in the end. - Isn't
pom.xml
a file that all maven projects need? - So what
build.repo
returns is the valuerepository
should get? (If the answer is yes, then you should make it clearer :)) - Perhaps it'd be better to just give two full examples of using
buildMaven
and using the double invocation (if we'd decide it's good to even document it).
- I'd start this document by writing that the derivation one would
Oh and I know you hate docbook, so am I. But, there's 1 advantage in docbook that's not available in our (current) markdown format: Take a look here:
nixpkgs/doc/languages-frameworks/go.xml
Lines 39 to 68 in 0826f2e
vendorSha256 = "1879j77k96684wi554rkjxydrj8g3hpp0kvxz03sd8dmwr3lh83j"; <co xml:id='ex-buildGoModule-1' /> | |
runVend = true; <co xml:id='ex-buildGoModule-2' /> | |
meta = with lib; { | |
description = "Simple command-line snippet manager, written in Go"; | |
homepage = "https://github.com/knqyf263/pet"; | |
license = licenses.mit; | |
maintainers = with maintainers; [ kalbasit ]; | |
platforms = platforms.linux ++ platforms.darwin; | |
}; | |
} | |
</programlisting> | |
</example> | |
<para> | |
<xref linkend='ex-buildGoModule'/> is an example expression using buildGoModule, the following arguments are of special significance to the function: | |
<calloutlist> | |
<callout arearefs='ex-buildGoModule-1'> | |
<para> | |
<varname>vendorSha256</varname> is the hash of the output of the intermediate fetcher derivation. | |
</para> | |
</callout> | |
<callout arearefs='ex-buildGoModule-2'> | |
<para> | |
<varname>runVend</varname> runs the vend command to generate the vendor directory. This is useful if your code depends on c code and go mod tidy does not include the needed sources to build. | |
</para> | |
</callout> | |
</calloutlist> | |
</para> |
And here: https://nixos.org/manual/nixpkgs/unstable/#ex-buildGoModule-1
Docbook can link lines in source code to documentation, which is really nice.
doc/languages-frameworks/maven.md
Outdated
version = "0.1"; | ||
name = "${pname}-${version}"; | ||
src = ./.; | ||
buildInputs = [ jdk maven makeWrapper ]; |
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.
Technically they aren't needed as they are referenced thanks to the makeWrapper
call.
buildInputs = [ jdk maven makeWrapper ]; | |
buildInputs = [ makeWrapper ]; |
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.
We're invoking mvn
in via PATH
in buildPhase
though. I figure a jdk
command is also necessary for mvn compile
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'll add a section on "Choosing the correct JDK"
The current mvn derivation allows overriding JAVA_HOME
❯ cat /nix/store/2hhmmj0vbb5d181nfx2mx3p7k54q44ij-apache-maven-3.6.3/bin/mvn
#! /nix/store/6737cq9nvp4k5r70qcgf61004r0l2g3v-bash-4.4-p23/bin/bash -e
export JAVA_HOME=${JAVA_HOME-'/nix/store/knh4n8fzrslyzgrw6p8nh5v07s0ycznc-openjdk-8u265-ga'}
exec "/nix/store/2hhmmj0vbb5d181nfx2mx3p7k54q44ij-apache-maven-3.6.3/maven/bin/mvn" "$@"
What i've done in the past is just make sure to set JAVA_HOME to the correct JDK (i.e. JDK8 vs JDK11).
An alternative approach would also be to overrideAttrs
@doronbehar thank you for your in depth review -- I will incorporate most/all of your feedback. For now, I will iterate using markdown purely due to my familiarity. I want to separate the issue of content vs. problems with how I use markup. A pragmatic approach may be to follow-up with another pull-request to convert it to docbook once the content is solid. |
Looking already pretty good. Feel free to link to your own project. |
1a340ab
to
e279c12
Compare
Thanks for the feedback everyone (@roberth & @doronbehar) If the documentation is pretty close to the mark, I'd like to be able to submit it and continue to iterate on 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.
It's getting better. But:
- Again, I tend to think we should not document the "double invocation" method.. But even if we do, it should be mentioned after mvn2nix-maven-plugin.
- Again, it would be easier IMO to understand it all, if the 1st expression the reader will see, is an expression of a derivation that uses
buildMaven
, in thelet repository =
.
e279c12
to
40a3228
Compare
Thanks again for the suggestions. |
0c3be23
to
49b7bee
Compare
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/rfc-0072-fcp-switch-to-commonmark-for-documentation/9560/4 |
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 notice you use a lot _
instead of a ``` where I'd use the later. Why?
doc/languages-frameworks/maven.md
Outdated
|
||
We will use the same repository we built above (either _double invocation_ or _buildMaven_) to setup a CLASSPATH for our JAR. | ||
|
||
### CLASSPATH |
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'm a little bit confused about this section. In the derivation of it you create a wrapper, and that calls Main as it seems. What's the difference between this and the last example expression?
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.
So fundamentally, your Java invocation needs to have all dependencies on the CLASSPATH.
CLASSPATH is the search path Java uses to lookup classes
The CLASSPATH can be set explicitly within a JAR which the subsequent section does through the help of Maven via the plugin via the MANIFEST file.
Here is the contents of the JAR and we see the CLASSPATH is set and expected at a fixed location relative to the JAR.
❯ unzip -q -c /nix/store/8d4c3ibw8ynsn01ibhyqmc1zhzz75s26-maven-demo-1.0/share/java/maven-demo-1.0.jar
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: nixbld
Class-Path: . ../../repository/com/vdurmont/emoji-java/5.1.1/emoji-jav
a-5.1.1.jar ../../repository/org/json/json/20170516/json-20170516.jar
Created-By: Apache Maven 3.6.3
Build-Jdk: 1.8.0_265
Main-Class: Main
The first approach though instead builds the JAR normally and then augments the makeWrapper to set the CLASSPATH via the command line.
You've given feedback on providing context on which is appropriate which I will do.
Fundamentally, if you are a nixpkgs author wrapping another project, the method by setting the CLASSPATH via makeWrapper is preferable since it's a bit more of a pain to create a patch file to change the project's pom.xml
If you are a project writer and using nix-shell or nix-build to build your project, it would be easier for you to modify your pom to add the required plugin.
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 don't read your comments, as I expect these explanations to be in the documentation.
doc/languages-frameworks/maven.md
Outdated
} | ||
``` | ||
|
||
### MANIFEST file via Maven Plugin |
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.
Is this a necessity to the above? It should be made clear in general, whether sections are targeted towards developers of a shell.nix
with maven, or casual contributors to Nixpkgs that just want to add a Java program to Nixpkgs, and compile it from source. Hence, I don't understand in what case one should need to "augment" the pom.xml
file.
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 added such sections.
doc/languages-frameworks/maven.md
Outdated
{ pkgs ? import <nixpkgs> { }, stdenv ? pkgs.stdenv, lib ? pkgs.lib | ||
, maven ? pkgs.maven, callPackage ? pkgs.callPackage | ||
, makeWrapper ? pkgs.makeWrapper, jre ? pkgs.jre }: |
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.
If it'll be clearer when a nix expression is targeted at contributors or shell.nix
writers, I should tell you when to remove these ?
defaults, since in many cases these are not recommended as callPackage
takes care of these defaults.
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.
These defaults exist because for the purpose of demonstration each file (https://github.com/fzakaria/nixos-maven-example) is individually runnable via nix-build
doc/languages-frameworks/maven.md
Outdated
mkdir -p $out/share/java | ||
|
||
# create a symbolic link for the repository directory | ||
ln -s ${repository} $out/repository |
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.
Why is this needed?
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.
Please see the comment above about the CLASSPATH value in the jar's MANIFEST file.
I think you mean |
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.
(Oops, I did a bunch of single comments instead of review ; sorry)
doc/languages-frameworks/maven.md
Outdated
mkdir -p $out/share/java | ||
|
||
# create a symbolic link for the repository directory | ||
ln -s ${repository} $out/repository |
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.
Please see the comment above about the CLASSPATH value in the jar's MANIFEST file.
159cf98
to
a812da3
Compare
No, I meant ``` - i.e |
@fzakaria I hope my review isn't to harsh :). I just want to make it clear for everyone in the future. Thanks for doing this anyway! |
b05139d
to
dcda7ad
Compare
@doronbehar thank you for the review. I'm hoping we can get this in soon; it's seen quite a few revisions. Improvements can continue to happen in subsequent pull-requests. It's definitely a place that will help others who want to use Java + Nix. The documentation is pretty thorough but does expect minimal understanding of how Java works which I consider acceptable since each language-support documentation isn't meant to expect 0 understanding of the language it's building upon. I'm happy to explain things 1:1 over some comments but I would like to push back a little on expecting 0 knowledge in the documentation. |
@roberth @doronbehar ping 👍 |
Content looks good, but it isn't incorporated into the manual yet. Line 89 in 8b6e981
and reference it.
Building the manual is documented here https://nixos.org/manual/nixos/stable/index.html#sec-writing-docs-building-the-manual |
@roberth I didn't even know that's how it works -- thanks for teaching me 👍 |
914e0da
to
3ae7bac
Compare
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.
Content really looks great now! Thanks @fzakaria 🎉.
Only some slight formatting nitpicks, if you don't mind :).
Add nice markdown documentation for how to use mvn2nix plugin and the buildMaven function within nixpkgs. Update doc/languages-frameworks/maven.md Co-authored-by: Robert Hensing <roberth@users.noreply.github.com> Apply suggestions from code review Co-authored-by: Doron Behar <doron.behar@gmail.com> Apply suggestions from code review Co-authored-by: Doron Behar <doron.behar@gmail.com> Apply suggestions from code review Co-authored-by: Doron Behar <doron.behar@gmail.com>
e92f82c
to
b9321ad
Compare
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.
🚀
Thanks again @fzakaria 🐳 . |
We did it! |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/maintained-usable-tooling-for-building-clojure-projects-in-nix/1556/6 |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/gnu-guix-1-2-0-released-2020-blog-gnu-guix/10167/7 |
Motivation for this change
Add nice markdown documentation for how to use mvn2nix plugin and the
buildMaven function within nixpkgs.
The goal is to have a thorough documentation similar to that of other languages.
ex. https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/ruby.section.md
Things done
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
)nix path-info -S
before and after)CC @jerith666 @volth @zimbatm @charles-dyfis-net