Maven fails to find local artifact
Asked Answered
U

17

151

Occasionally maven complains that a particular dependency, which is built and packaged locally, cannot be found in the local repository while building another project that has it as a dependency. We get an error like:

Failed to execute goal on project X: Could not resolve dependencies for project X: Failure to find Y in [archiva repository] was cached in the local repository, resolution will not be reattempted until the update interval of internal has elapsed or updates are forced ->

Where X is the project being built, and Y is the supposedly missing artifact. If you look in the local repository, the artifact is there. This artifact is never installed in our archiva repository, so the problem is purely based in the local repository.

We have tried various profiles in settings.xml, and of course "mvn -U". Neither do any good, nor should they because this artifact never goes any further than the local repository.

The only two things that seem to work are to wait a very long time until maven smartens up, or to completely delete the local repository. Presumably the waiting option is related to the aforementioned update interval.

We have experienced this problem with maven 3.0.2 and 3.0.3. We are using Archiva 1.0.3 (but again this shouldn't be a factor). Any help would be greatly appreciated.

Unmentionable answered 20/9, 2012 at 16:44 Comment(7)
Is Maven logging anything while or just before the "waiting?" I.e. is it attempting to connect to an unreachable repository? Also, are the problematic artifacts "-SNAPSHOT"?Soler
Maven doesn't log anything other than the error I mentioned above. And yes this is a snapshot dependency.Unmentionable
See #1349103Soler
Have you installed the build package before you try to build the second project?Radius
I like how the error message is a run-on, not a grammatically correct sentence. This way, we don't know for sure if it cannot find Y or if Y was cached locally, or both. Anyway, I have a similar problem. I was able to resolve it with the -U option because my dependencies are in my company's internal repo. Why aren't the artifacts you need deployed to your company's internal repository?Bohner
For these kinds of problem, it's always worth checking that you're actually looking for the correct version. You can use mvn dependency:resolve (maven.apache.org/plugins/maven-dependency-plugin/…) to check that specific dependencies are available, and mvn help:effective-pom to view the pom as it is when maven runs, i.e. including all the content inherited from parent poms and the like (maven.apache.org/plugins/maven-help-plugin/…)Meggs
It is possible that same version of Y (the missing artifact) is also being re-built when you are trying to build X. So in that case it is highly probable that the repository has not yet updated the component Y and hence build of X fails. To be sure - try to do mvn install of the artifact Y locally in the build system. And then start the build of X.Perverted
P
112

The local Maven repo tracks where artifacts originally came from using a file named "_maven.repositories" in the artifact directory. After removing it, the build worked. This answer fixed the problem for me.

Pasturage answered 22/1, 2014 at 12:52 Comment(8)
For me it was a file named "_remote.repositories". I removed it and it worked! Thank for the tricks!Fadden
Thx the file named _remote.repositories was also present. it happened to me when our nexus stop having network connection so it cant obtain the dependenciesOatis
The provided solution does work. However, I am interested in why this problem occurrs at all. Could anybody provide me with a quick explanation? Do I have to do something differently?Ethiop
If you want to bypass this origin check once (without deleting the metafiles), try passing aether.enhancedLocalRepository.trackingFilename=some_dummy_file_name to the dependency resolution process; easiest way is to add a -D system property to the invocation command.Children
@Ethiop IMO the link in the answer provides a pretty good explanation :)Children
For me neither deleting '_maven.repositories' nor 'remote.repositories' worked, so deleted contents of '.m2' and did a clean install.Dancer
This worked for me. I know that the original repository atm is offline and eclipse/maven cannot track the artifact (it exists only in one place). Good candidate to put in local repo :).Ribal
Hello! I am having a similar issue, however I can´t find any of those files using cmd search. Could you please share in what folder was it located, so that i can check manually if there is another similar file?Unstring
A
63

As the options here didn't work for me, I'm sharing how I solved it:

My project has a parent project (with its own pom.xml) that has many children modules, one of which (A) has a dependency to another child (B). When I tried mvn package in A, it didn't work because B could not be resolved.

Executing mvn install in the parent directory did the job. After that, I could do mvn package inside of A and only then it could find B.

Assuntaassur answered 13/7, 2017 at 5:56 Comment(3)
THANK YOU! this was driving me crazy. mvn clean package jboss-as:deploy was working when I executed on a single line, but not when I did them separately.Albano
Thanks, this solution saved me from wasting timeAnnaleeannaliese
If only I hadn't deliberately broken the parent project during a refactoring, and am now trying to get the individual components to work, one after the other. Did anyone ever figure out why building the parent is the only way to get the repo lookup to work as expected?Photoflood
C
28

Even in offline mode, maven will check remote repositories if there is a _remote.repositories marker for the dependency. If you need to operate in offline mode, you may need to delete these files.

The simple shell command below deletes these marker files. This is safe to do if you only use offline mode for the machine. I would NOT do this on a machine that needs to pull files down from the web.

I have used this strategy on a build server that is disconnected from the web. We have to transfer the repository to it, delete the marker files and then run in offline mode.

On Linux / Unix you can delete the remote repository marker files this way:

cd ~/.m2
find . -name "_remote.repositories" -type f -delete
Cark answered 16/11, 2017 at 19:51 Comment(3)
This solution worked for me, for a dependency I copied over from another computer which is not available in a central repository. The command though misses a few characters. Here is the full command: find . -name "_remote.repositories" -type -f -deleteSymphonist
Or, instead of deleting, you should be able to "misguide" Maven to not look at the _remote.repositories file by passing -Daether.enhancedLocalRepository.trackingFilename=some_dummy_file_name to the process. (Didn't try on an actual Maven build, but works when invoking Maven programmatically; so the former should also work)Children
I did this finding and deleting specific dependencies (jars) not found by Maven, since they were listed and manageable to to (< 10). This was due to a misconfig pointing to a remote Nexus not currently available (as I understood..). So no actual need to sweep all repo for deletion. Anyway this solution saved the day. It work for me.Tumultuous
J
14

Maven remembers when it didn't find something. The key is "resolution will not be reattempted until the update interval of internal has elapsed or updates are forced ->"

The quick solution is to delete your local "repository" subdirectory for the problem artifact - assuming you have fixed the problem with it. :)

mvn -U will force update from remote repository - again, assuming you have now populated remote with said artifact.

Jevons answered 17/9, 2014 at 21:58 Comment(1)
Such a simple fix, so little attention paid to it. (clap)Sherri
S
13

When this happened to me, it was because I'd blindly copied my settings.xml from a template and it still had the blank <localRepository/> element. This means that there's no local repository used when resolving dependencies (though your installed artifacts do still get put in the default location). When I'd replaced that with <localRepository>${user.home}\.m2\repository</localRepository> it started working.

For *nix, that would be <localRepository>${user.home}/.m2/repository</localRepository>, I suppose.

Seating answered 20/1, 2014 at 2:27 Comment(1)
${user.home}\.m2\repository is the default so removing the empty tag should work alike.Dibrin
H
10

If you have <repositories/> defined in your pom.xml apparently your local repository is ignored.

Hebrews answered 17/1, 2020 at 19:55 Comment(0)
D
3

Catch all. When solutions mentioned here don't work(happend in my case), simply delete all contents from '.m2' folder/directory, and do mvn clean install.

Dancer answered 20/7, 2019 at 1:2 Comment(1)
Yep. this answer worked but dependency:go-offline did not work for me. So misleading.Employee
A
2

Even I faced this issue and solved it with 2 ways:

1) In your IDE select project and clean all projects then install all the maven dependencies by right clicking on project -> go to maven and Update project dependencies select all projects at once to install the same. Once this is done run the particular project

2) Else What you can do is check in the pom.xml for the dependencies for which you are getting error and "mvn clean install" those dependent project first and the install maven dependencies of the current project in which you facing issue. By this the dependencies of the local project will be build and jars will be created.

Albie answered 28/5, 2019 at 12:10 Comment(0)
H
1

In my case I needed project Y to be a WAR to be deployed through Tomcat, as well as it needed to be a JAR to be able to add it as a dependency in project X.

So in project Y's pom.xml, I added this plugin to create a JAR along with the WAR:

<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>3.2.2</version>
    <configuration>
        <attachClasses>true</attachClasses>
        <classesClassifier>classes</classesClassifier>
    </configuration>
</plugin>

And while adding the dependency of project Y in project X's pom.xml, I had to add a classifier:

<dependency>
    <groupId>groupId.of.project.Y</groupId>
    <artifactId>project.Y</artifactId>
    <version>1.0-SNAPSHOT</version>
    <classifier>classes</classifier>
</dependency>

Note: when you build project Y, you will see 2 packagings in the target folder: project-Y.war and project-Y-classes.jar, so that's why while importing you are specifying the classes classifier to import the JAR and not the WAR.

Holeandcorner answered 16/12, 2020 at 8:5 Comment(0)
N
0

I run to the similar problem when my new project depend on oracle jdbc jar(which I have installed in my local repository and work well for other projects). I tried -U option ,deleting .lastupdate file or the whole directory and downlaod again,but it did not work. finally,I deleted the directory and installed it locally again,it works.

Nollie answered 10/3, 2015 at 7:37 Comment(0)
M
0

One of the errors I found around Maven is when I put my settings.xml file in the wrong directory. It has to be in .m2 folder under your user home dir. Check to make sure that is in the right place (along with settings-security.xml if you are using that).

Miso answered 7/11, 2015 at 2:36 Comment(0)
B
0

I had DependencyResolutionException in Ubuntu Linux when I've installed local artifacts via a shell script. The solution was to delete the local artifacts and install them again "manually" - calling mvn install:install-file via terminal.

Backbreaking answered 16/1, 2017 at 4:5 Comment(0)
M
0

This happened because I had http instead of https in this:

<repository>
    <id>jcenter</id>
    <name>jcenter-bintray</name>
    <url>https://jcenter.bintray.com</url>
</repository>
Misdemeanor answered 17/4, 2020 at 22:39 Comment(0)
W
0

check if if your artifact Y have packaging set to "jar". If you have defined it as "war" by error or copy paste, it will show this strange "was cached in the local repository, resolution will not be reattempted until the update interval of internal has elapsed or updates are forced". I would expect something like "artifact Y is war, jar type expected".

Whimsicality answered 14/8, 2020 at 8:24 Comment(1)
this solution is partially correct, which pointed my towards the right answer. In my case I wanted Y to be WAR so I packaged it both as JAR and WAR, and imported the JAR in project X. Check my answer for a detailed approach to do this.Holeandcorner
T
-1

I had the same error from a different cause: I'd created a starter POM containing our "good practice" dependencies, and built & installed it locally to test it. I could "see" it in the repo, but a project that used it got the above error. What I'd done was set the starter POM to pom, so there was no JAR. Maven was quite correct that it wasn't in Nexus -- but I wasn't expecting it to be, so the error was, ummm, unhelpful. Changing the starter POM to normal packaging & reinstalling fixed the issue.

Tenrec answered 3/6, 2020 at 11:50 Comment(1)
This answer would probably have been better as a comment, since it isn't a direct answer to the question.Shiny
D
-2

Here is the long Solution to the problem (Not Quick fix but will work if no other solution)

You're going to hate me for saying this but this is the truth about open source projects like eclipse. Because Open source is modular and allows you to build and develop a project in many ways with many tools such as maven, spring boot, options for xml or groovy, different eclipse updates & Etc. The problem is that eclipse allows you to run the project with missing maven builds because the IDE is smart enough to resolve dependencies using a remote_repository where it stores and catches the jar files that is not properly built on the project.

Because of this feature, You may actually have local build issues but just like DNS servers; if the solution is not found in the local directory, Eclipse will look for a solution in it's remote cached repository. When you delete the remote_repository and let Maven rebuild it a second time, The project may end up creating more errors and not build a second time or may possibly rebuild a cache that was missing. But that is unlikely.

So the long answer to fix your solution.

This is a project architecture issue!

SOLUTION: What you need to do is look in to all your dependant project's pom.xml file and the maven dependencies folder in your local project and try to resolve all the missing dependency jars in your maven dependency folder. If you have a referenced library, I suggest moving those jars into your local project's maven dependency folder.

You have to work your way into solving every child project and then navigate into your root project and fix every single project by using Maven -> Build -> clean install (check off "skip tests" & "resolve workspace artifacts") until every project builds with a clean success.

most likely, when you force update your entire solution to all your projects, you will get a list of errors that you have the IDE auto-resolve. The auto-resolve will refer to a easy reference to fix the issue. But to deploy, you have to manually fix the project because Eclipse, Spring & Maven will work well together but there are maybe a few things they don't agree on. So, you have to play diplomat in those situations and figure it out.

That's the sad truth.

All said, I have a list of problems in my project. I have this issue. The war file generated has empty jar folders and the build is not clean without errors unless i force it. The WAR file generate will run a 404 error on tomcat server production and my angular application will throw a Cors-Error when executing the API.

All the errors on my front end project is artificial because the root of all issues is the WAR file generated. It did not generate with dependencies, the Main project did not execute in tomcat and tomcat server cannot run the spring initializer to deploy the cors-policy on the server to allow my angular application to communicate. But all in all, development environment works fine with no issues.

So that is my long ended solution for this thread.

Dhobi answered 31/8, 2021 at 2:53 Comment(0)
U
-4

In my case I had to add mavenLocal() in root level gradle dependency

mavenCentral()
mavenLocal()
Unmanned answered 25/4, 2021 at 7:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.