2

I have a maven multi-module project whose parent POM states:

<modules>
  <module>ui</module>
  <module>controller</module>  <!-- Depends on ui module -->
</modules>

The following runs fine:

project-root> mvn clean package

However problems arise if I try:

project-root/controller> mvn clean package

The error reports the ui artifact as an unresolved dependency.

Yes, I realize that this question has been asked before. However it has no clear answer (the accepted answer for that instance is only a workaround). This behavior is explained away as a difference between dependency resolution and reactor builds. A post about Maven 3 suggests that it is resolved in that released. I am using Maven 3.0.3 and see no relief. Maven 3.0.4's release notes don't suggest a change in this behavior.

How do you handle such a situation? Is the only recourse to do a build from the project-root every time?

Community
  • 1
  • 1
Sri Sankaran
  • 8,120
  • 4
  • 38
  • 47

1 Answers1

1

The problem you are faced with is that you try to call a build from a sibling, in which case the dependency resolution will be done against your local repository.

There are several solutions to your problem. The first one is to go to your root and do a mvn install. Afterwards, you should be able to go to your controller and do mvn clean package. But I recommend to go to your root and build specifically the controller module:

mvn -pl controller clean package

But the prerequisite is to do an mvn install before that.

Alain Pannetier
  • 9,315
  • 3
  • 41
  • 46
khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • As you will note from my question, I am aware of the `mvn install` first *workaround*. Ideally I would like to be able to simply `mvn clean package` at `ui` module followed by `mvn clean package` at the `controller` module. – Sri Sankaran May 19 '12 at 19:07
  • 1
    You can also check if -am helps better ? mvn -am -pl controller clean package ? – khmarbaise May 21 '12 at 20:51
  • Using the `-am` switch results in all required modules (`ui` in my case) being (unnecessarily) rebuilt every time `controller` is built. Yes, I even tried without running the `clean` phase. – Sri Sankaran May 22 '12 at 15:36