0

I have a simple problem but being a novice with Maven it's unclear which is the best practice to solve this problem.

A project I'm working has a dependency to manage archives which is the following: net.sf.sevenzipjbindings.

This dependency is made by two artifacts: a pure Java one, which provides the Java interface and another one which is the native underlying code which has many flavours according to the operating system.

At the moment I'm packaging the jar built by maven with all the natives for all the platforms but I'd like to be able to do something like:

  • when working (so compile goal if I understand correctly) on the project use the all-platforms artifact (so that I can work seamlessly from multiple operating systems
  • when packaging build 3 different JAR with dependencies composed by the Java interface + a specific platform artifact

This sounds rather simple from my point of view but I'm struggling to understand what I should do and what are the best practices in general. Since here there is no different or modular functionality (like isolating part of the code into a separated module), just a replacement for underlying dynamic libraries.

Jack
  • 131,802
  • 30
  • 241
  • 343
  • It's a bit difficult to understand exactly what you're after, but if your project is a library, the usual approach would be to package your own jar with only the dependency on the Java interface and require downstream to include an appropriate native driver, otherwise include them all in your application jar. – chrylis -cautiouslyoptimistic- Jul 07 '16 at 05:55
  • If you need having different dependencies this means you have to have different modules which handle that. – khmarbaise Jul 07 '16 at 07:21
  • @chrylis: my project is not a library, is an application. Basically, assuming that dependencies are A B C D and E, I need to compile by using AB and export 3 JAR with AC, AD and AE. But these dependencies are taken directly from the Maven repository, they are not my own packages. – Jack Jul 07 '16 at 13:26
  • Then if you want it to run everywhere, you should package all of the dependencies into your application. – chrylis -cautiouslyoptimistic- Jul 07 '16 at 16:27
  • @chrylis: of course, but that's not the point. I want to distribute different JARs for different platforms, because the native libraries are taking 95% of the final size of the application so I'd like to split them. – Jack Jul 07 '16 at 16:31

1 Answers1

0

It sounds like you want a multi-module Maven build:

- myapp
  - myapp-engine
  - myapp-windows
  - myapp-linux

The myapp-engine module should depend on external-library-api, and the myapp-windows module should depend on myapp-engine and external-library-windows. Since you're actually only running the application on a specific OS for any given launch (even in development), there's no reason not to launch the OS-specific module. Modern IDEs should have no trouble debugging into a separate module in a multi-module build.

chrylis -cautiouslyoptimistic-
  • 75,269
  • 21
  • 115
  • 152