0

I have a maven project structured like this:

parent
|- pom.xml
|- module1/ (extends parent)
| |- pom.xml

Inside the parent pom.xml:

  <modelVersion>4.0.0</modelVersion>
  <groupId>com.company</groupId>
  <artifactId>parent</artifactId>
  <version>0.0.0-SNAPSHOT</version>
  <packaging>pom</packaging>
  <name>parent POM</name>

  <modules>
    <module>module1</module>
  </modules>

And inside the module pom.xml:

  <parent>
    <groupId>com.company</groupId>
    <artifactId>parent</artifactId>
    <version>0.0.0-SNAPSHOT</version>
  </parent>

When I do a install with the parent pom, I get an error:

Could not find artifact com.company:parent:pom:0.0.0-SNAPSHOT

When I install the parent pom first, then the entire project it works:

C:\dev\parent> mvn clean install -N
C:\dev\parent> mvn clean install

How do I configure maven to install the parent pom before any modules?

I've also attempted to restructure my project like in this answer but it is still not working: https://stackoverflow.com/a/9517053/4104760

George
  • 2,820
  • 4
  • 29
  • 56

1 Answers1

1

When you execute Maven, it'll build the current pom and all its modules (recursive) So it is only going down, it is not going back up to include the parents

It seems like you ran Maven like this

parent/module1> mvn validate (validate is enough to see the effect)

Running it like this will trigger both pom files:

parent> mvn validate

Robert Scholte
  • 11,889
  • 2
  • 35
  • 44
  • the `validate` step is the first step of `install`. When I do `parent> mvn install` it basically does `parent> mvn validate compile test etc.. install` – George Jan 08 '20 at 23:22
  • I've updated the post with working directory to be more clear. – George Jan 08 '20 at 23:26