Search code examples
javamavenpom.xmlthreetenbp

Not able to import classes from Three Ten Backport


This seems like a simple task, but I have already spoken with two of my co-workers about this and no one understands where the problem lies. We have a multi-module Maven project with a root POM file from which all the child modules inherit. In the root POM file I added this dependency, which I copied from the Three Ten Backport website:

<dependency>
  <groupId>org.threeten</groupId>
  <artifactId>threetenbp</artifactId>
  <version>1.3.8</version>
</dependency>

This is under the dependencyManagement section where all the other dependencies are located. All other dependencies work fine. But when I try to import the Three Ten classes in a class within a module, I get an error.

import org.threeten.bp.LocalDateTime;

When I try to build the project, the build fails, with this error message.

error: package org.threeten.bp does not exist

I have already tried the following:

  1. mvn clean install on the project directory, which works fine before I add the import statement, but fails after I add the import statement.
  2. Running "maven update" on all modules in Spring Tool Suite.
  3. Searched ~/.m2/repository for the org.threeten.bp package but none of the files were there in the local repository.

What could be the problem here? Why is the Three Ten Backport dependency not being installed with all the others? It's on Maven Central, so I don't believe I need to add any repositories to my POM file, or do I?


Solution

  • Adding the <dependency> to the <dependencyManagement> section doesn't by itself add the dependency to the project, it just established a default version for child projects to use.

    You also need to add the <dependency> to the main <dependencies> section (without the <version> if also added to <dependencyManagement>) for it to be used by the project.