0

The m2eclipse plugin has a project option “Resolve dependencies from Workspace projects” that tells downstream Maven projects to use the target/classes directory of the upstream dependencies instead of using packaged jars. Is there any way to tell mvn to do the same thing?

For example, if I have have two projects, foo and bar, and bar depends on foo, then on the command line I have to package and install foo before I can run bar:

cd ~/foo
mvn package install
cd ~/bar
mvn prepare-package
java -cp target/classes:$(mvn -o -q -Dmdep.outputFile=/dev/stdout dependency:build-classpath) Bar

But I want to avoid packaging all the projects because 1) it’s a lot of redundant I/O, and 2) if I save in Eclipse and run from the command line it’s easy to forget to package all the projects again, and then I’ll waste time wondering why my changes didn’t work.

So is there any way to change pom.xml so that the mvn command uses the unpacked classes from mvn prepare-package instead of the mvn install repository?

yonran
  • 18,156
  • 8
  • 72
  • 97

1 Answers1

0

Why don't you put foo and bar in a multi-module project like this:

PROJ
  + foo
  + bar

And, with such structure, you are not supposed to build foo and bar separately. Simply build at the PROJ level and everything is fine. Dependencies is resolved within the reactor and you don't need to install them one by one explicitly.

It doesn't save the "extra IO" you mentioned, but honestly the only difference is only creating the JAR which is in fact minimal compared to other things happened.

Your second argument doesn't hold too. In fact you should NOT mix the command line target directory with Eclipse. Many features in Eclipse is sensitive to external change in output folder. If you do what you mentioned (save in eclipse, and expected to pick up the updated class file in command line build), the command line build is going to "corrupt" (in Eclipse's perspective) the output data and cause problem in Eclipse. (That's why people come up with way to separate the output folder instead : https://stackoverflow.com/a/54366009/34088 )

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
Adrian Shum
  • 38,812
  • 10
  • 83
  • 131