When maven says “resolution will not be reattempted until the update interval of MyRepo has elapsed”, where is that interval specified?

前端 未结 19 1113
迷失自我
迷失自我 2020-11-22 16:49

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 fr

相关标签:
19条回答
  • 2020-11-22 17:32

    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>
    
    0 讨论(0)
  • 2020-11-22 17:32

    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>
    
    0 讨论(0)
  • 2020-11-22 17:34

    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 讨论(0)
  • 2020-11-22 17:36

    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.

    0 讨论(0)
  • 2020-11-22 17:37

    For Intellij users the following worked for me:

    Right click on your package

    Maven > Reimport 
    

    and

    Maven > Generate Sources and Update Folders
    
    0 讨论(0)
  • 2020-11-22 17:37

    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

    0 讨论(0)
提交回复
热议问题