Skip to content
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

Introduce buildMaven derivation #17

Open
wants to merge 2 commits into
base: test
Choose a base branch
from
Open

Introduce buildMaven derivation #17

wants to merge 2 commits into from

Conversation

fzakaria
Copy link
Owner

Simplify the process of building a runnable JAR by including a useful derivation for others to use.

It requires that the project under question is setup specifically to use the repositoryLayout however if so; it makes on-boarding onto mvn2nix super easy.

{ pkgs ? import <nixpkgs> {} }:
let
  mvn2nix = import
    (fetchTarball "https://github.com/fzakaria/mvn2nix/archive/master.tar.gz")
    { };
  buildMavenRepository = mvn2nix.buildMavenRepository;
  buildMaven = mvn2nix.buildMaven;
  mavenRepository =
    buildMavenRepository { generated = import ./dependencies.nix; };
in buildMaven {
  jdk = pkgs.jdk11_headless;
  generated = import ./dependencies.nix;
  repository = mavenRepository;
  # we set the source directory one level higher
  # this is just for this example
  src = ../../.;
}

At the moment, I've decided to only include buildMaven to create a runnable JAR artifact since that seems the most likely usage for someone wanting to bring their Maven application into a Nix derivation.

We can consider alternative derivations that simply generate a JAR.

Simplify the process of building a runnable JAR by including a
useful derivation for others to use.

It requires that the project under question is setup specifically
to use the `repositoryLayout` however if so; it makes onboarding onto
mvn2nix super easy.
@fzakaria
Copy link
Owner Author

@DerGuteMoritz curious for your thoughts.

# @param generated: The nix expression generated by mvn2nix
# @param repository: A maven repository; see buildMavenRepository above.
# @param src: The src files to feed into maven
buildMaven = { maven ? pkgs.maven, jdk ? pkgs.jdk, generated
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might make sense to split this:
buildMavenJar & buildMavenExecutable or something and have buildMavenExecutable create a linkFarm of the repository & output of buildMavenJar

@fzakaria
Copy link
Owner Author

@roberth also since you have good insights :)

@fzakaria
Copy link
Owner Author

An unfortunate way mvn2nix operates now is that the test dependencies are part of the runtime closure because the full maven repository is included.

Not sure a great solution here without restarting that whole problem about using aether etc..

@roberth
Copy link
Contributor

roberth commented Aug 26, 2020

You could figure out some rudimentary scope info by invoking maven more than once. For example

  1. mvn -Dmaven.test.skip=true
  2. scan the temporary maven repo
  3. mvn
  4. scan again

The difference between the scans will tell you something about test dependencies. My example won't help you distinguish between plugin dependencies and build dependencies though, but there's probably something you can do with the goals to tease out more information about that.
It won't be perfect, but it might be a safe optimization in most cases.

You could also use the pom and aether for determining runtime dependencies but still use repo scanning to figure out plugin dependencies on top of that.

Ultimately this is also a problem for the project author to solve. They probably haven't been shipping entire repos or sources only. Most projects will build an assembly or fat jar or something, so they should have an installPhase that only copies the distributable files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants