801

With maven, I occasionally hit an artifact that comes from some 3rd-party repo that I haven't built or included in my repository yet.

I'll get an error message from the maven client saying that an artifact can't be found:

Failure to find org.jfrog.maven.annomojo:maven-plugin-anno:jar:1.4.0 in http://myrepo:80/artifactory/repo was cached in the local repository, resolution will not be reattempted until the update interval of MyRepo has elapsed or updates are forced -> [Help 1]

Now, I understand what this means, and can simply re-run my command with -U, and things usually work fine from there on out.

However, I find this error message to be extremely unintuitive and am trying to spare my co-workers some headaches.

I am trying to figure out if there is some place that I can modify this update interval setting.

  1. Is the update interval that is mentioned in this error message a client-side or server-side setting?
  2. If client-side, how do I configure it?
  3. If server-side, does anyone know how/if Nexus/Artifactory expose these settings?
8bitjunkie
  • 12,793
  • 9
  • 57
  • 70
cprice404
  • 8,019
  • 3
  • 15
  • 3
  • 38
    I got the same error message after adding 1 more dependency to my pom.xml. For me this is clearly a BUG. I don't understand why this happens! If I add dependencies to my project and I run mvn compile than it should just download the jar files. This behaviour is totally nonsense! – Robert Reiz Jun 12 '13 at 17:42
  • 3
    related http://stackoverflow.com/questions/4701532/force-maven-update – Paul Verest Mar 05 '15 at 02:40
  • 2
    I just recently experienced this and after all the answers I've read, another additional step is to **re-import the project** in Eclipse (in my case). It was too weird that Eclipse kept on bugging me with a plugin that is not in my `pom.xml`. – Rey Libutan Jun 06 '15 at 04:35
  • For me, it turned out a particular repo was linked to GitHub and the url went offline (getting 404). I updated the repo to our internal server and it worked. – cbmeeks Mar 12 '20 at 14:45
  • I changed version in pom.xml. Then jar downloaded and working. – Devendra Singraul Apr 16 '20 at 13:18

25 Answers25

387

I used to solve this issue by deleting the corresponding failed to download artifact directory in my local repo. Next time I run the maven command the artifact download is triggered again. Therefore I'd say it's a client side setting.

Nexus side (server repo side), this issue is solved configuring a scheduled task. Client side, this is done using -U, as you already pointed out.

Peter Hall
  • 53,120
  • 14
  • 139
  • 204
Christian Achilli
  • 5,547
  • 2
  • 25
  • 24
  • 13
    "I use to solve this issue by deleting the corresponding failed to download artifact directory in my local repo." This worked for me. I'm using Netbeans as well. –  Apr 06 '12 at 20:02
  • 48
    If Maven notes that the cached artifact is invalid, why cannot it solve this on its own? – Stefan Nov 16 '16 at 09:55
  • 1
    what does "configuring a scheduled task" mean and "this is done using -U", can you please put these into objective Eclipse UI terms? – user2568374 May 04 '17 at 13:04
  • 1
    I assume you mean Eclipse IDE. The theory is you need to download the latest SNAPSHOT. To do that you need to add the '-U' parameter to your maven command, e.g. mvn clean compile -U. Now, you can run this maven command either through command line or through Eclipse by ticking the 'always update snapshot' box. Not sure, I use intellij these days. The 'configuring a scheduled task' part refers to a particular configuration you want to have on your Nexus server. This latter is nothing to do with Eclipse as such. – Christian Achilli May 08 '17 at 10:00
  • 15
    This does not answer OPs actual question. – 8bitjunkie Jun 27 '17 at 14:00
  • This works well in jenkins too. Go to project -> configure -> "build" tab -> goals and options. There you can set the -U. – nettie Aug 24 '18 at 20:54
  • Thanks. This is very useful.. specially while I am just starting with maven. – Mr. Noddy Dec 04 '19 at 08:49
  • `-U,--update-snapshots` Forces a check for updated releases and snapshots on remote repositories – Julien Mar 02 '20 at 13:26
  • @Stefan It cannot solve on its own because many times it is not an issue with Maven's local repository but there is an issue in jar or repository connection causing corrupt files download. So, Maven waits for some time so that the issue gets resolved. – damndemon Apr 06 '20 at 06:44
  • Deleting from local m2 folder did solved this issue for me. – Daidipya Apr 05 '22 at 12:20
181

What basically happens is, according to the default updatePolicy of maven, maven will fetch the jars from the repo on a daily basis. So if during the first attempt your Internet was not working, then it would not try to fetch this jar again until 24hours has passed.

Resolution:

Either use

mvn -U clean install

(where -U will force update the repo)

or use

<profiles>
    <profile>
      ...
      <repositories>
        <repository>
          <id>myRepo</id>
          <name>My Repository</name>
          <releases>
            <enabled>false</enabled>
            <updatePolicy>always</updatePolicy>
            <checksumPolicy>warn</checksumPolicy>
          </releases>
         </repository>
      </repositories>
      ...
    </profile>
  </profiles>

in your settings.xml

levininja
  • 3,118
  • 5
  • 26
  • 41
Sanjeev Guglani
  • 2,114
  • 1
  • 7
  • 13
  • This actually helped me with system scoped dependency, avoiding `NoClassDefFoundError` during runtime. – FonzTech Oct 08 '20 at 14:58
  • Due to some reason, cleaning .m2 didnt work for me, after adding updatePolicy tag in settings.xml file, artifacts were downloaded – pmann Apr 28 '21 at 14:25
  • 2
    what kind of a dumbo decided THAT was sensible default? – Enerccio Mar 20 '23 at 19:34
147

you can delete the corresponding failed artifact directory in you local repository. And also you can simply use the -U in the goal. It will do the work. This works with maven 3. So no need to downgrade to maven 2.

kds
  • 28,155
  • 9
  • 38
  • 55
  • 2
    Why messing with the repository configuration when it can be so simple? – Koraktor Jul 24 '13 at 09:09
  • 12
    Please read the question carefully before you answer. OP is asking how to set time interval, not how to force an update. – i3ensays Mar 04 '14 at 22:22
  • 3
    Not an answer to the question but this is what people need when they hit this exception. Because when you are working on a local lib development, best is to delete such a lib instead of allowing the interval confuse you. – mcvkr Nov 28 '17 at 14:35
  • We should have valid repositories added under `~/.m2/settings.xml/` to resolve this issue with -U options – Kanagavelu Sugumar Aug 13 '19 at 09:29
71

I had a related problem, but Raghuram's answer helped. (I don't have enough reputation yet to vote his answer up). I'm using Maven bundled with NetBeans, and was getting the same "...was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced -> [Help 1]" error.

To fix this I added <updatePolicy>always</updatePolicy> to my settings file (C:\Program Files\NetBeans 7.0\java\maven\conf\settings.xml)

<profile>
  <id>nexus</id>
  <!--Enable snapshots for the built in central repo to direct -->
  <!--all requests to nexus via the mirror -->
  <repositories>
    <repository>
      <id>central</id>
      <url>http://central</url>
      <releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>
      <snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
    </repository>
  </repositories>
 <pluginRepositories>
    <pluginRepository>
      <id>central</id>
      <url>http://central</url>
      <releases><enabled>true</enabled><updatePolicy>always</updatePolicy></releases>
      <snapshots><enabled>true</enabled><updatePolicy>always</updatePolicy></snapshots>
    </pluginRepository>
  </pluginRepositories>
</profile>
Peter Hall
  • 53,120
  • 14
  • 139
  • 204
MrDrews
  • 2,139
  • 2
  • 22
  • 22
55

While you can resolve this with a clean install (overriding any cached dependencies) as @Sanjeev-Gulgani suggests with mvn -U clean install

You can also simply remove the cached dependency that is causing the problem with

mvn dependency:purge-local-repository -DmanualInclude="groupId:artifactId"

See mvn docs for more info.

sfletche
  • 47,248
  • 30
  • 103
  • 119
  • 7
    But why does Maven abort the build? Why doesn't it just take the cached dependency that is there in your local repository? Why do you have to delete it to make Maven fetch it?! – dokaspar Sep 11 '20 at 07:06
  • Only answer that actually works for **release** versions of artifacts. – user11153 May 26 '22 at 14:48
49

According to the settings reference:

updatePolicy: This element specifies how often updates should attempt to occur. Maven will compare the local POM’s timestamp (stored in a repository’s maven-metadata file) to the remote. The choices are: always, daily (default), interval:X (where X is an integer in minutes) or never.

Example:

<profiles>
    <profile>
      ...
      <repositories>
        <repository>
          <id>myRepo</id>
          <name>My Repository</name>
          <releases>
            <enabled>false</enabled>
            <updatePolicy>always</updatePolicy>
            <checksumPolicy>warn</checksumPolicy>
          </releases>
         </repository>
      </repositories>
      ...
    </profile>
  </profiles>
  ...
</settings>
8bitjunkie
  • 12,793
  • 9
  • 57
  • 70
Raghuram
  • 51,854
  • 11
  • 110
  • 122
  • 8
    Thanks for the reply; however, I've experimented quite a bit with the "updatePolicy" setting, and it seems to have no effect on "Not Found" / "Failure Cached" / "resolution will not be reattempted" error. – cprice404 Feb 02 '11 at 17:00
14

This works after you delete the related dependency from your local maven repository

/user/.m2/repository/path
Pravin Bansal
  • 4,315
  • 1
  • 28
  • 19
9

This error can sometimes be misleading. 2 things you might want to check:

  1. Is there an actual JAR for the dependency in the repo? Your error message contains a URL of where it is searching, so go there, and then browse to the folder that matches your dependency. Is there a jar? If not, you need to change your dependency. (for example, you could be pointing at a top level parent dependency, when you should be pointing at a sub project)

  2. If the jar exists on the remote repo, then just delete your local copy. It will be in your home directory (unless you configured differently) under .m2/repository (ls -a to show hidden if on Linux).

MattC
  • 5,874
  • 1
  • 47
  • 40
  • 4
    This is not relevant to OP's question. The reason why the error is shown is not the point. OP wants to know how to set the retry interval. – 8bitjunkie Jun 27 '17 at 14:03
  • 1
    This may be an implied issue behind OP's post and turned out to be my issue. Turned out I had a typo in my which by reviewing option one lead me down the right path. – James Oravec Jul 24 '17 at 21:04
  • 1
    The question is how to set the interval ? – smilyface Oct 10 '17 at 05:34
8

If you are using Eclipse then go to Windows -> Preferences -> Maven and uncheck the "Do not automatically update dependencies from remote repositories" checkbox.

This works with Maven 3 as well.

ashoka
  • 651
  • 6
  • 10
7

You need to delete all "_maven.repositories" files from your repository.

Riadh
  • 1,088
  • 2
  • 12
  • 25
6

I had a similar error with a different artifact.

<...> was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced

None of the above described solutions worked for me. I finally resolved this in IntelliJ IDEA by File > Invalidate Caches / Restart ... > Invalidate and Restart.

NoraT
  • 71
  • 1
  • 4
  • Nice one. [This article explicates further](https://www.baeldung.com/maven-clear-cache) on how to clear the cache for maven from cli. – Mavaddat Javid Mar 23 '23 at 11:57
4

For Intellij users the following worked for me:

Right click on your package

Maven > Reimport 

and

Maven > Generate Sources and Update Folders
Emeric
  • 6,315
  • 2
  • 41
  • 54
3

If you use Nexus as a proxy repo, it has "Not Found Cache TTL" setting with default value 1440 minutes (or 24 hours). Lowering this value may help (Repositories > Configuration > Expiration Settings).

See documentation for more info.

chipiik
  • 1,970
  • 15
  • 15
3

Maven has updatePolicy settings for specifying the frequency to check the updates in the repository or to keep the repository in sync with remote.

  • The default value for updatePolicy is daily.
  • Other values can be always / never/ XX (specifying interval in minutes).

Below code sample can be added to maven user settings file to configure updatePolicy.

<pluginRepositories>
    <pluginRepository>
        <id>Releases</id>
        <url>http://<host>:<port>/nexus/content/repositories/releases/</url>
        <releases>
            <enabled>true</enabled>
            <updatePolicy>daily</updatePolicy>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </pluginRepository>             
</pluginRepositories>
  • 3
    This does not answer OP's question. OP is clear that they understand what the problem is and how to update their local m2 repository. OP is asking where the interval is located and how to change it. There is no mention of any IDE at all. You have not read the question. – 8bitjunkie Jun 27 '17 at 13:44
  • 1
    @8bitjunkie This answers quite directly the question: `If client-side, how do I configure it?`. This answer is not about any IDE feature. It's mvn only repository configuration. The `updatePolicy` is the interval the OP is asking about. – montrivo Apr 03 '20 at 13:06
3

To finally answer the title question: It is (a client side setting) in (project, profile or settings)

[plugin]?[r|R]epository/[releases|snapshots]/updatePolicy

... tag.

The (currently, maven: 3.6.0, but I suppose "far backwards" compatible) possible values are :

/**
 * Never update locally cached data.
 */
public static final String UPDATE_POLICY_NEVER = "never";
/**
 * Always update locally cached data.
 */
public static final String UPDATE_POLICY_ALWAYS = "always";
/**
 * Update locally cached data once a day.
 */
public static final String UPDATE_POLICY_DAILY = "daily";
/**
 * Update locally cached data **every X minutes** as given by "interval:X".
 */
public static final String UPDATE_POLICY_INTERVAL = "interval";

The current (maven 3.6.0) evaluation of this tag is implemented as follows:

public boolean isUpdatedRequired( RepositorySystemSession session, long lastModified, String policy )
{
    boolean checkForUpdates;
    if ( policy == null )
    {
        policy = "";
    }
    if ( RepositoryPolicy.UPDATE_POLICY_ALWAYS.equals( policy ) )
    {
        checkForUpdates = true;
    }
    else if ( RepositoryPolicy.UPDATE_POLICY_DAILY.equals( policy ) )
    {
        Calendar cal = Calendar.getInstance();
        cal.set( Calendar.HOUR_OF_DAY, 0 );
        cal.set( Calendar.MINUTE, 0 );
        cal.set( Calendar.SECOND, 0 );
        cal.set( Calendar.MILLISECOND, 0 );
        checkForUpdates = cal.getTimeInMillis() > lastModified;
    }
    else if ( policy.startsWith( RepositoryPolicy.UPDATE_POLICY_INTERVAL ) )
    {
        int minutes = getMinutes( policy );
        Calendar cal = Calendar.getInstance();
        cal.add( Calendar.MINUTE, -minutes );
        checkForUpdates = cal.getTimeInMillis() > lastModified;
    }
    else
    {
        // assume "never"
        checkForUpdates = false;
        if ( !RepositoryPolicy.UPDATE_POLICY_NEVER.equals( policy ) )
        {
            LOGGER.warn( "Unknown repository update policy '{}', assuming '{}'",
                    policy, RepositoryPolicy.UPDATE_POLICY_NEVER );
        }
    }
    return checkForUpdates;
}

..with:

private int getMinutes( String policy )
{
    int minutes;
    try
    {
        String s = policy.substring( RepositoryPolicy.UPDATE_POLICY_INTERVAL.length() + 1 );
        minutes = Integer.valueOf( s );
    }
    catch ( RuntimeException e )
    {
        minutes = 24 * 60;
        LOGGER.warn( "Non-parseable repository update policy '{}', assuming '{}:1440'",
                policy, RepositoryPolicy.UPDATE_POLICY_INTERVAL );
    }
    return minutes;
}

...where lastModified is the (local file) "modified timestamp" of an/each underlying artifact.


In particular for the interval:x setting:

  • the colon : is not that strict - any "non-empty" character could do it (=, , ...).
  • negative values x < 0 should yield to "never".
  • interval:0 I would assume a "minutely" (0-59 secs. or above...) interval.
  • number format exceptions result in 24 * 60 minutes (~"daily").

..see: DefaultUpdatePolicyAnalyzer, DefaultMetadataResolver#resolveMetadata() and RepositoryPolicy

xerx593
  • 12,237
  • 5
  • 33
  • 64
2

How I got this problem,

When I changed from Eclipse Juno to Luna, and checkout my maven projects from SVN repo, I got the same issues while building the applications.

What I tried? I tried clean Local repository and then updating all the versions again using -U option. But my problem continued.

Then I went to Window --> Preferences -> Maven --> User Settings --> and clicked on Reindex button under Local Repository and wait for the reindex to happen.

That's all, the issue is resolved.

Lyju I Edwinson
  • 1,764
  • 20
  • 20
2

In my case the solution was stupid: I just had incorrect dependency versions.

1

Somewhat relevent.. I was getting

"[ERROR] Failed to execute goal on project testproject: Could not resolve dependencies for project myjarname:jar:1.0-0: Failure to find myjarname-core:bundle:1.0-0 in http://repo1.maven.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]"

This error was caused by accidentally using Maven 3 instead of Maven 2. Just figured it might save someone some time, because my initial google search led me to this page.

Darshana
  • 2,462
  • 6
  • 28
  • 54
sdanzig
  • 4,510
  • 1
  • 23
  • 27
  • 2
    What if your project forces you to use Maven 3? Do you have any clue as to what changed between the two versions? – Xr. Jul 23 '12 at 09:27
  • 1
    This is exactly what my problem was. No idea why Maven 3 is so different from 2. Thank you for posting this and saving me from wasting any more time searching for a solution. – CatsAndCode Dec 24 '12 at 15:17
  • how to install maven2 instead of maven3? – trillions Feb 28 '14 at 20:52
  • Very generic question.. what operating system? For Ubuntu, you can do "sudo apt-get install maven2"... or for any Linux/UNIX, you can just download the archive and compile it yourself, adding it to your path. Try: http://shameerarathnayaka.blogspot.com/2012/01/how-to-install-maven2maven3-in-ubuntu.html – sdanzig Mar 01 '14 at 07:17
  • This worked for me & in fact I link back to this from my [answer here](https://stackoverflow.com/questions/4650460/maven-could-not-resolve-dependencies-artifacts-could-not-be-resolved/24049252#24049252). – shiri Jun 07 '18 at 14:25
  • This is also not an answer to the OP’s question of where these timeouts are and whether they are configurable (and what they default to). – mirabilos Oct 25 '18 at 15:47
1

I had the same error, (resolution will not be reattempted...) but I had different requirements, as I have files in my local repository, that are currently not available remotely (old outdated libraries and internal libraries), and my company nexus system is down, but they do exist in my .m2 repos.

Maven still refused to build, producing the same error above.

For the offending libraries, I just removed the corresponding file:

_remote.repositories

exmple path: users\[username]\.m2\[offending jar path]\[versionnumber]\_remote.respositories

knowing that these files are only available locally.

Note: Long term resolution, I should probably get our previous nexus system up and running, and for those jars that are legacy, check them into the project under a lib folder (or something like that)

Ed Manners
  • 459
  • 4
  • 8
1

I have resolved it!

I have encountered this issue earlier and after reviewing some comments it worked. we only have to correct settings.xml file under {m2_home}/.m2

**<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository>.m2/repository</localRepository>
<profiles>
    <profile>
      <repositories>
        <repository>
          <id>projectid</id>
          <url>http://localhost</url>
          <name>Project name</name>
          <releases>
            <enabled>false</enabled>
            <updatePolicy>always</updatePolicy>
            <checksumPolicy>warn</checksumPolicy>
          </releases>
         </repository>
      </repositories>
    </profile>
  </profiles>
</settings>**

and execute maven clean install command.

**/maven_home/mvn -f project_directory/pom.xml -DskipTests clean install**
0

I had this problem and the comprehensive descriptions proposed in this helped me to fix it.

The second declared problem was my issue. I used a third-party repository which I had just added it do the repository part of the pom file in my project. I add the same repository information into pluginrepository to resolve this problem.

0

I ran into the same problems with uploaded third party libraries on my private repository. Sometimes the described fixes worked for me, but sometimes they did not.

I think the root cause of the problem is a missing pom.xml file for the artifact. (The pom.xml for the third party artifact not your pom.xml in your project). I assume Maven expects for every artifact a pom.xml, so it can resolve the dependencies for all artifacts. Sometimes it works without a pom.xml, but sometimes it does not (I have not identified, when it does not).

I use Nexus3 as a private repository. When you upload an artifact, you can check an option to generate a pom.xml file for the artifact.

hami
  • 443
  • 5
  • 13
0

Changing the localRepository path in my settings.xml solved the issue

Mert Aksoy
  • 372
  • 1
  • 4
  • 12
0

Go to your Pom file and right-click and scroll down then click on maven to open the settings.xml file (as you see from the image) and add the following code (to your settings.xml file) then save and close and wait for maven to reload.

 <mirrors>
   <mirror>
     <id>my-mirror</id>
       <url>https://repo.maven.apache.org/maven2/</url>
     <mirrorOf>central</mirrorOf>
 </mirror>
</mirrors>

Then refresh/reload your pom file/project.

N:B You may have to go to your main spring boot class and Hoover on top of @SprinBootApplication then click on the suggestion to add Maven dependency ......

This will reinstall your local maven dependencies which you are likely to have lost.

enter image description here

Godwin Tusime
  • 101
  • 1
  • 4
-1

Make sure that the artifact you are looking for is exist , if its on your local project run : cd .. cd project name mvn clean install

Then you will have it locally.

for better practice do : mvn clean deploy so you can use it again without this problem

Tal Hakmon
  • 475
  • 5
  • 6