Package does not exist error when building with Maven

10,294

Solution 1

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.

Solution 2

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

Share:
10,294
Alexis Dufrenoy
Author by

Alexis Dufrenoy

I'm a french software engineer and software architect. I work mainly with Java (JavaEE, Spring), Javascript (Angular, ExtJS) and RDBMS (MySQL, PostSQL, Oracle, Sybase, Teradata). I also have knowledge in Typescript, C, C++, shellscript, social network application programming (Facebook, Opensocial, Twitter), image processing, payment solutions implementation (Paypal) and more. About personal projects: I started the french wikibook on programming (yeah, back in 2004 or something). I was very involved at different levels in Wikipedia and sister projects for 5 years, until 2008. Consumed most of my spare time, then. But it was worth it. I'm also a real free software maniac. Free as in free speech... My other center of interest are photography (I got a Canon 7D I'm having real fun with. I took the picture of a polar fox I'm using as an avatar with my older 350D), cooking (I'm french, after all :-) and seeing museums, especially art (I can't grow tired of the Marmottan Museum and its unique Monet paintings collection). My 2 mother tongues are french and german, and apparently I'm not all so bad in english... :-). Beside France, I worked in Germany and Switzerland (where I also lived).

Updated on June 04, 2022

Comments

  • Alexis Dufrenoy
    Alexis Dufrenoy almost 2 years

    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?