111

I have a maven project that contains several modules. In Eclipse (Juno, with m2e) it seems to compile fine. But when I do a maven install on one of the modules, the build fails immediately.

Parent pom:

  <groupId>com.sw.system4</groupId>
  <artifactId>system4-parent</artifactId>
  <version>${system4.version}</version>
  <packaging>pom</packaging>
  <name>System 4 Parent Project</name>
  <modules>
    <module>system4-data</module>
     ...others...
  </modules>
  <properties>
    <system4.version>0.0.1-SNAPSHOT</system4.version>
    <spring.version>3.2.3.RELEASE</spring.version>
    ... others...
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${spring.version}</version>
        <scope>runtime</scope>
      </dependency>
    ... lots of others ...
    </dependencies>
  </dependencyManagement>

Child pom:

  <parent>
    <groupId>com.sw.system4</groupId>
    <artifactId>system4-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <artifactId>system4-data</artifactId>
  <dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <scope>runtime</scope>
    </dependency>
    ... lots of others...
  </dependencies>

When I build, I get the following output:

[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]
[ERROR]   The project com.sw.system4:system4-data:0.0.1-SNAPSHOT (C:\work\eclips
e_workspaces\systemiv\system4-parent\system4-data\pom.xml) has 8 errors

[ERROR]     'dependencies.dependency.version' for org.springframework:spring-cor
e:jar is missing. @ line 16, column 16

... others omitted for clarity ...

I dont understand why it doesn't even attempt to compile. Ive tried removing the runtime scope from parent and child, and it makes no difference. Please help!

1

20 Answers 20

82

If anyone finds their way here with the same problem I was having, my problem was that I was missing the <dependencyManagement> tags around dependencies I had copied from the child pom.

4
  • 11
    and I always wondered what was the use of dependencyManagement tag until now.. This worked for me.. I was missing this tag in parent pom.
    – Lord Nick
    Commented Nov 29, 2017 at 15:56
  • 3
    This feels like the answer that will apply to most people coming here Commented Jan 25, 2019 at 10:18
  • sort of explanation stackoverflow.com/questions/2619598/… :( Commented Sep 25, 2019 at 8:30
  • 4
    you made my day
    – Peter S.
    Commented Dec 6, 2019 at 21:26
64

A couple things I think you could try:

  1. Put the literal value of the version in the child pom

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>3.2.3.RELEASE</version>
      <scope>runtime</scope>
    </dependency>
    
  2. Clear your .m2 cache normally located C:\Users\user.m2\repository. I would say I do this pretty frequently when I'm working in maven. Especially before committing so that I can be more confident CI will run. You don't have to nuke the folder every time, sometimes just your project packages and the .cache folder are enough.

  3. Add a relativePath tag to your parent pom declaration

    <parent>
      <groupId>com.mycompany.app</groupId>
      <artifactId>my-app</artifactId>
      <version>1</version>
     <relativePath>../parent/pom.xml</relativePath>
    </parent>
    

It looks like you have 8 total errors in your poms. I would try to get some basic compilation running before adding the parent pom and properties.

4
  • 1
    Just to clarify - the other 7 errors that I excluded were all of the same sort - i.e. dependencies.dependency.version is missing for (other dependency) Commented Jun 27, 2013 at 8:58
  • 7
    <relativePath> was the key for me: one module was not in the default child location but one subdirectory deeper. Thanks.
    – Glenn
    Commented Aug 15, 2013 at 13:30
  • 5
    Another reason why Maven complains about missing dependency is when dependency declared in parent pom has <type> that doesn't correspond to the type that the child pom is looking for.
    – zdenekca
    Commented May 8, 2014 at 19:54
  • Thanks. 2 fixed it for me. Commented Jun 9, 2021 at 15:12
8

Right, after a lot of hair tearing I have a compiling system.

Cleaning the .m2 cache was one thing that helped (thanks to Brian)

One of the mistakes I had made was to put 2 versions of each dependency in the parent pom dependencyManagement section - one with <scope>runtime</scope> and one without - this was to try and make eclipse happy (ie not show up rogue compile errors) as well as being able to run on the command line. This was just complicating matters, so I removed the runtime ones.

Explicitly setting the version of the parent seemed to work also (it's a shame that maven doesn't have more wide-ranging support for using properties like this!)

  <parent>
    <groupId>com.sw.system4</groupId>
    <artifactId>system4-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>

I was then getting weird 'failed to collect dependencies for' errors in the child module for all the dependencies, saying it couldn't locate the parent - even though it was set up the same as other modules which did compile.

I finally solved things by compiling from the parent pom instead of trying to compile each module individually. This told me of an error with a relatively simple fix in a different module, which strangely then made it all compile.

In other words, if you get maven errors relating to child module A, it may actually be a problem with unrelated child module Z, so look there. (and delete your cache)

1
  • Cleaning the whole local repo is a little too radical solution... Just remove the subtree concerned by your project is enough. An other post on the same subject : stackoverflow.com/questions/2389602/…
    – Yanflea
    Commented Jun 27, 2013 at 17:02
5

In theory, maven does not allow to use a property to set a parent version.

In your case, maven can simply not figure out that the 0.0.1-SNAPSHOT version of your parent pom is the one that is currently in your project, and so it tries to find it in your local repo. It probably finds one since it is a snapshot, but it is an old version that probably not contains your Dependency Management section.

There is a workaround though :

Simply change the parent section in the child pom with this :

<parent>
    <groupId>com.sw.system4</groupId>
    <artifactId>system4-parent</artifactId>
    <version>${system4.version}</version>
    <relativePath>../pom.xml</relativePath>  <!-- this must match your parent pom location -->
</parent>
1
  • The problem is that the parent project has other subprojects (modules) that compile ok. The relativePath default correctly points to the location of the parent pom. Commented Jun 27, 2013 at 8:57
3

Make sure the value in the child's project/parent/version node matches its parent's project/version value

1
  • This. You probably pulled remote changes which updated versions everywhere but your new module
    – coffman21
    Commented Apr 3 at 15:59
3

I had the same error, I forgot to add the child dependencies in the <dependencyManagement>. For example in the parent pom:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.sw.system4</groupId>
            <artifactId>system4-data</artifactId><!-- child artifact id -->
            <version>${project.version}</version>
        <dependency>

        <!-- add all third party libraries ... -->

    </dependencies>
<dependencyManagement>
1
  • 1
    This worked for me. On the child pom.xml the maven archtype 35 does not wrap it with <dependencyManagment> tag. So I had to manually add that and doing mvn clean on the project is working fine now. Thanks
    – Mahder
    Commented May 3, 2022 at 14:18
1

In my case I had the same dependency listed twice in the same pom.xml. Make sure it's only used once.

1

For those using the org.codehaus.mojo:flatten-maven-plugin: Be sure to set a flattenMode which keeps the dependencyManagement if you still want to import the pom (e.g. resolveCiFriendliesOnly). Otherwise, the plugin will remove the dependencyManagement section.

1

For me the problem was that an intermediate parent had the dependency.

So my setup is:

parent.pom <- intermediateparent.pom <- child.pom

The <dependencyManagement> is defined in parent.pom

When <dependency> is defined in intermediateparent.pom and child.pom, then it is defined twice in child.pom and the error occurs.

Removing the dependency from intermediateparent.pom and only defining it in child.pom helped in my case.

1

For me the problem was related to classifier in my dependencyManagement, I had dependencies of the project with <classifier> (and <version> of course). I removed <classifier> from dependencyManagement which solved the problem.

1
  • This was the issue for me: from what I understand, if you specify a classifier in the dependency management, then you also need to specify it in the dependencies.
    – nyg
    Commented May 11, 2023 at 14:45
0

You must build parent module before doing child module.

0

What just worked for was to delete the settings.xml in the .m2 folder: this file was telling the project to look for a versión of spring mvc and web that didn't exist.

0

I had the same problem and I rename the "repository" folder on ".m2" (something like repositoryBkp the name is not important is just in case something goes wrong) and create a new "repository" folder, then I re run maven and all the project compile successfully

0

If you are using modules and need lombok for child module you need to explicitly declare version as well like :

<dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.24</version>
            <optional>true</optional>
        </dependency>
    </dependencies>

It helped in my case.

0

In my case I was putting tomcat decency then I got the error and this what I used.

<dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-core</artifactId>
            <version>9.0.44</version>
        </dependency>
0

Most probably your spring-framework-bom might not be existing. Recheck for the version if it has ".RELEASE" at the end.

0

In my case I was using the example direct from spring security at:

https://docs.spring.io/spring-security/reference/getting-spring-security.html

The above had the following as the version:

<version>{spring-security-version}</version>

instead of:

<version>${spring-security.version}</version>

Changing the above in my pom.xml resolved the issue.

0

In my case, my artifact's <groupId> is different because of my negligence.

parentPom.xml
<dependencyManagement>
 <dependency>
      <groupId>org.dom4j</groupId>
      <artifactId>dom4j</artifactId>
      <version>${dom4j.version}</version>
</dependency>
</dependencyManagement>

sonPom.xml
 <dependency>
      <groupId>dom4j</groupId>
      <artifactId>dom4j</artifactId>
</dependency>

So I compiled the project when I corrected the groupId.Hope this help you.

0
For me spring dependency no working because i forgot to add spring boot parent project in pom.xml

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.6.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
0

In my case I can't append spring depedencies without versions

Required dependecies:

<dependency>
  <groupId>org.projectlombok</groupId>
  <artifactId>lombok</artifactId>
  <optional>true</optional>
</dependency>
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

And dependecies will inject after i add spring as :

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.0.9</version>
    <relativePath/>
  </parent>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.