'dependencies.dependency.version' is missing error, but version is managed in parent

JavaMaven 3

Java Problem Overview


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!

Java Solutions


Solution 1 - Java

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.

Solution 2 - Java

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.

Solution 3 - Java

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)

Solution 4 - Java

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>

Solution 5 - Java

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>

Solution 6 - Java

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

Solution 7 - Java

You must build parent module before doing child module.

Solution 8 - Java

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.

Solution 9 - Java

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

Solution 10 - Java

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

Solution 11 - Java

for me the problem related to classifier in my dependencyManagement i had dependencies of the project with (and "version" off curse) i removed from dependencyManagement which solved the problem

Solution 12 - Java

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionfancyplantsView Question on Stackoverflow
Solution 1 - JavaBrian BlainView Answer on Stackoverflow
Solution 2 - JavaShermsView Answer on Stackoverflow
Solution 3 - JavafancyplantsView Answer on Stackoverflow
Solution 4 - JavaYanfleaView Answer on Stackoverflow
Solution 5 - JavaTerranView Answer on Stackoverflow
Solution 6 - JavainorView Answer on Stackoverflow
Solution 7 - JavatraeperView Answer on Stackoverflow
Solution 8 - JavaCamiloView Answer on Stackoverflow
Solution 9 - JavaConejoView Answer on Stackoverflow
Solution 10 - JavakolobokView Answer on Stackoverflow
Solution 11 - JavaodedView Answer on Stackoverflow
Solution 12 - JavaMatthiasView Answer on Stackoverflow