Alexis Dufrenoy
Alexis Dufrenoy

Reputation: 11946

Package does not exist error when building with Maven

I'm trying to build a pom.xml for a project I'm forking. The original project uses a pom hierarchy I can't use, so I need to write a new pom.xml.

Now, I get an annoying package xxx does not exist, for example for org.apache.commons.logging, but in my pomxml, I get the dependency:

<dependencyManagement>
  <dependencies>
    ...
    <dependency>
      <groupId>commons-logging</groupId>
      <artifactId>commons-logging</artifactId>
      <version>1.1.1</version>
    </dependency>
    ...
  <dependencies>
<dependencyManagement>

Obviously, Maven is failing on imports like:

import org.apache.commons.logging.Log;

My pom.xml has not any parent. I'm using Maven 2 with Java 5. any clue?

Upvotes: 2

Views: 10813

Answers (2)

quartzde
quartzde

Reputation: 638

If you don't have a pom hierarchy you don't need <dependencyManagement> just <dependencies>. Remove the surrounding <dependencyManagement>.

Upvotes: 2

Assen Kolov
Assen Kolov

Reputation: 4393

The dependencyManagement entry above tells maven: each time a project declares a dependency like this:

<dependencies>
 ...
<dependency>
  <groupId>commons-logging</groupId>
  <artifactId>commons-logging</artifactId>
  <!-- notice there is no version -->
</dependency> 

use the version form dependencyManagement: 1.1.1.

It is very useful to have dependencyManagement in your main pom, so that all projects inheriting from this pom will use consistently the same version. Changing it at this one place will cause all inheriting projects to be use another version the next time they are built.

Keep dependencyMangement in the main pom, add dependency without version in your projects.

Upvotes: 4

Related Questions