-3

I have a maven project in Eclipse with a bunch of local project dependencies.

Building with the Maven assembly plugin or shade plugin is a pain because I first have to build and install all of the local project dependencies before I can build my main project.

Does m2e provide a way to script a sequence of arbitrary maven commands? I know I can script everything from the command line, I just don't know where m2e's instance of maven is installed, and I'd like to avoid installing a separate instance.

Andy
  • 7,885
  • 5
  • 55
  • 61

1 Answers1

1

Have you considered creating a multi-module Maven project that "contains" the dependencies? That would allow you to build just the container and Maven automatically takes care of building the component modules. Eclipse's m2e supports multi-module builds so there wouldn't be anything special to do for Eclipse.

E-Riz
  • 31,431
  • 9
  • 97
  • 134
  • Ah, that might work for me. I'll check it out, thanks! – Andy Jan 04 '16 at 20:46
  • I tried that, but there were two things I didn't like about it: 1) how would you ever include a module in other multi-module projects? 2) module A had test depdendency on module B, and maven failed to include A's classes when building B's tests in the multi-module project. Worked fine when I shell scripted the module build order and ran `mvn package` on the main project. – Andy Jan 05 '16 at 20:03
  • I remember the first job I had where we used a multi-module maven project, we always got all kinds of weird errors and I ended up hating maven. Now I started using it in non-multi-module projects and I've been pleasantly surprised how well it works... – Andy Jan 05 '16 at 20:04
  • The test dependency thing is tricky; basically you have to configure A to produce a test JAR, then declare the dependency on A as a `test-jar` dependency. See http://stackoverflow.com/a/1733745/639520 – E-Riz Jan 05 '16 at 20:10
  • I see Maven as a necessary evil; necessary because the Java community has latched on to it, evil because it's, well, evil. – E-Riz Jan 05 '16 at 20:11
  • @ERiz actually it was half my fault about the testDependency, module A needed to have JUnit as a compile dep, rather than a test dep, yet I wasn't seeing errors, I think because it was already built successfully by Eclipse using extra Eclipse classpath stuff. – Andy Jan 05 '16 at 20:14
  • @ERiz that is, Module A exports classes in a *non-test jar* that Module B needs to use to compile its tests. – Andy Jan 05 '16 at 20:16
  • Yeah it is a necessary evil, but thankfully scripting the module build sequence isn't that hard, so multi-module maven projects aren't a necessary evil for me. – Andy Jan 05 '16 at 20:17
  • @ERiz aha, I figured out that if I use "project aggregation" with a multi-module project (i.e. no parent POM inheritance), the module that contains the shade plugin will automatically build the shaded jar after everything else when I run `mvn install` on the "parent" pom. So it works! – Andy Jan 05 '16 at 20:30