0

I have observed the following maven behavior in my project which does not make sense to me. Here is the essence of what is going on.

Lets say I have a project with with two modules

  • com.example.foo.jar
  • com.example.bar.jar bar depends on foo
  • both share a common parent project that is includes maven module

When my local .m2 is empty and therefore foo and bar are not installed.

  • In the project/ directory mvn clean verify works and the build is successful
  • in bar/ directory mvn initialize does not work and I get an error message saying that maven could not resolve bar's dependency on foo

So why can maven build the project when I invoke it from the project folder but not from an individual module?

project/
  pom.xml
  foo/
    pom.xml
  bar/
    pom.xml

I am trying to avoid the mvn install hack discussed here http://developer-blog.cloudbees.com/2012/12/maven-and-hack.html

Cœur
  • 37,241
  • 25
  • 195
  • 267
ams
  • 60,316
  • 68
  • 200
  • 288

1 Answers1

1

You can build submodules in the reactor:

mvn -pl bar package -am

You'll need to include -am to also build foo, as otherwise Maven has nowhere to get foo's jar from.

See Maven Modules + Building a Single Specific Module for more details.

Community
  • 1
  • 1
Joe
  • 29,416
  • 12
  • 68
  • 88