51

Background

Trying to add a Java library to the local Maven repository using a clean install of Apache Maven 3.1.0, with Java 1.7. Here is how the Java archive file was added:

mvn install:install-file \
  -DgroupId=net.sourceforge.ant4x \
  -DartifactId=ant4x \
  -Dversion=0.3.0 \
  -Dfile=ant4x-0.3.0.jar \
  -Dpackaging=jar

This created the following directory structure:

$HOME/.m2/repository/net/sourceforge/ant4x/
├── 0.3.0
│   ├── ant4x-0.3.0.jar.lastUpdated
│   └── ant4x-0.3.0.pom.lastUpdated
└── ant4x
    ├── 0.3.0
    │   ├── ant4x-0.3.0.jar
    │   ├── ant4x-0.3.0.pom
    │   └── _remote.repositories
    └── maven-metadata-local.xml

The project's pom.xml file references the dependent project (the tree above) as follows:

<properties>
  <java-version>1.5</java-version>
  <net.sourceforge.ant4x-version>0.3.0</net.sourceforge.ant4x-version>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
...
<dependency>
  <groupId>net.sourceforge</groupId>
  <artifactId>ant4x</artifactId>
  <version>${net.sourceforge.ant4x-version}</version>
  <scope>provided</scope>
</dependency>

Problem

After running mvn compile, the following error was returned (full log on Pastebin):

[ERROR] Failed to execute goal on project ant4docbook: Could not resolve dependencies for project net.sourceforge:ant4docbook:jar:0.6-SNAPSHOT: Failure to find net.sourceforge:ant4x:jar:0.3.0 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]

The documentation notes a number of issues that could be present, however none of these appear to apply.

Ideas

I tried the following, as per the documentation:

  1. Copy default settings to user's home directory for Maven:
    cp /opt/apache-maven-3.1.0/conf/settings.xml $HOME/.m2/.
  2. Edit the user's settings.xml file.
  3. Update the value for the local repository:
    ${user.home}/.m2/repository
  4. Save the file.

I also tried the following commands:

mvn -U
mvn clear -U

I tried using Maven 3.0.5, but that failed, too.

Question

How do you force Maven to use the local version of the library, rather than trying to seek out a library that is not yet available to download?

Related

Related questions and information that did not resolve the issue:

Community
  • 1
  • 1
Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
  • I was receiving this error when attempting to download SNAPSHOT dependencies from a self-hosted Maven repo. The reason was because I had not enabled download of SNAPSHOT dependencies from the repo. To do this, you need add a specific section to the POM of the project that is in need of downloading SNAPSHOT versions of dependencies from your repo. See this answer for more: https://stackoverflow.com/questions/7715321/how-to-download-snapshot-version-from-maven-snapshot-repository – Matt Jan 13 '22 at 19:27

2 Answers2

18

Change:

<!-- ANT4X -->
<dependency>
  <groupId>net.sourceforge</groupId>
  <artifactId>ant4x</artifactId>
  <version>${net.sourceforge.ant4x-version}</version>
  <scope>provided</scope>
</dependency>

To:

<!-- ANT4X -->
<dependency>
  <groupId>net.sourceforge.ant4x</groupId>
  <artifactId>ant4x</artifactId>
  <version>${net.sourceforge.ant4x-version}</version>
  <scope>provided</scope>
</dependency>

The groupId of net.sourceforge was incorrect. The correct value is net.sourceforge.ant4x.

Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
  • I could not find any such artifact registered with maven. I tried adding this one of my mavne, it is still not working. Exception: Missing artifact net.sourceforge.ant4x:ant4x:jar:0.3.0:provided . Are you sure? – Gyanendra Dwivedi Sep 11 '13 at 03:42
  • It is because Maven try to find any jar either at central repo (available on internet) or from local repo (configured in pom profile). On ether of the place, this jar should be there or it could be installed using **maven:install** command. – Gyanendra Dwivedi Sep 11 '13 at 03:52
3

The scope <scope>provided</scope> gives you an opportunity to tell that the jar would be available at runtime, so do not bundle it. It does not mean that you do not need it at compile time, hence maven would try to download that.

Now I think, the below maven artifact do not exist at all. I tries searching google, but not able to find. Hence you are getting this issue.

Change groupId to <groupId>net.sourceforge.ant4x</groupId> to get the latest jar.

<dependency>
  <groupId>net.sourceforge.ant4x</groupId>
  <artifactId>ant4x</artifactId>
  <version>${net.sourceforge.ant4x-version}</version>
  <scope>provided</scope>
</dependency>

Another solution for this problem is:

  1. Run your own maven repo.
  2. download the jar
  3. Install the jar into the repository.
  4. Add a code in your pom.xml something like:

Where http://localhost/repo is your local repo URL:

<repositories>
    <repository>
        <id>wmc-central</id>
        <url>http://localhost/repo</url>
    </repository>
    <-- Other repository config ... -->
</repositories>
Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
Gyanendra Dwivedi
  • 5,511
  • 2
  • 27
  • 53
  • 2
    The suggestion to add the jar directly to the classpath using Eclipse doesn't solve the Maven issue here. If someone uses this approach, then they are essentially giving up on trying to use Maven as their build tool. – twindham Dec 04 '14 at 17:37
  • @twindham I agree that earlier answer was kind of hack and really not a good practice. I have updated the answer with one more option, which is widely used. – Gyanendra Dwivedi Dec 12 '14 at 16:27
  • nice edit, this new answer is definitely a solution that allows the user to keep using maven as their build tool. – twindham Dec 12 '14 at 21:09