1

In my application built by Maven I have two platform-specific dependencies that are mutually exclusive. During the project's build I would like to build two runnable jars where one jar contains one dependency and the second jar contains the other dependency.

My first thought was to create two build profiles where each one contains one of the dependencies and the Maven Assembly or Shade plugin to build a runnable jar. Unfortunately that does not seem to work because only one of the jars will build. I tried enabling both on the command line (-Pprofile1,profile2), setting both activeByDefault to true but still no luck.

Before I try to work around it by creating two project submodules to do the builds, is there a way to build two runnable jars with different dependencies in the same Maven project?

jzonthemtn
  • 3,344
  • 1
  • 21
  • 30
  • 1
    Your strategy with two profiles must work; you're doing something wrong if only one gets built. Show a pom.xml with the setup, if possible. BTW, `activeByDefault` flag is a bit quirky. Perhaps you're using the same ID for the execution, in both profiles? – Andrei May 18 '17 at 19:50
  • @Andrei Thanks for confirming that - I will do it again and double check everything. – jzonthemtn May 18 '17 at 20:54
  • No worries; regarding my comment about execution IDs : if you're simply declaring the plugin in both profiles (with no `èxecution` tag) then I think one overrides the other because they all run on the execution `default-jar` (I think this is the ID of the default execution). If this is the case then simply declare two separate executions, one in each profile, making sure to specify different IDs. – Andrei May 18 '17 at 20:59
  • Similar question is at :http://stackoverflow.com/questions/8726884/create-multiple-runnable-jars-with-depencies-included-from-a-single-maven-proj . – Shailesh Pratapwar May 19 '17 at 02:01
  • Your thought about using two different modules is the best and cleanest way to solve the problem (separation of concerns). The profiles will not work in the end. To build a release you will simply call `mvn clean deploy` and get everything build what you need. This is only possible using the two module setup. If you are using with profiles this simple call will not work. – khmarbaise May 19 '17 at 06:56
  • I suggest you share your `pom.xml` so we could have a look. One reason why the execution of the plugin in the two profiles would "not work" would be, if the `` in both profiles has the same ``, as, in effect, the second one would override the first one's execution. – carlspring May 19 '17 at 11:06

1 Answers1

1

For those interested, using two separate modules was the best solution for me. There is one project ("main") that contains all the code. There are two other projects where each project declares the dependency it requires for its specific platform and the project "main." Each project then builds a runnable jar for its platform.

jzonthemtn
  • 3,344
  • 1
  • 21
  • 30