versions-maven-plugin doesn't retrieve the latest version on nexus?

553 views Asked by At

I am trying to use (partly successfully) the versions-maven-plugin to retrieve latest release/snapshot versions from my local and nexus repositories to update maven projects. When running this plugin to update versions, I have noticed the following behaviour:

Even though I know that there is a newer version in nexus, but not in my local repository, it doesn't find the latest version, but the latest from the local repo. If I delete all the maven-metadata*.xml files from my local repo for the artifact I want to update, it downloads the latest maven-metadata*.xml files and correctly finds the latest version.

I see that it's using 2.0.6 og all maven APIs, and the method that drives the whole update mechanism is retrieveAvailableVersions() from interface ArtifactMetadataSource and implemented by MavenMetadataSource.

MY QUESTION How can I alter the code of this plugin to always download the latest maven-metadata*.xml files such that I get the latest versions? Or if there is any other reliable method which can make this happen..

Thanks for your time.

1

There are 1 answers

0
Gogi On BEST ANSWER

I have actually found the solution myself and created a goal which I run before running goals which updates my pom.xml files: This is the method which updates the metadata for all repositories. If you need the whole goals, please let me know:

 public void updateMetadata(Artifact artifact){        
    getLog().info("Updating metadata for: " + artifact.getGroupId()+":"+artifact.getArtifactId());
    RepositoryMetadata metadata = new ArtifactRepositoryMetadata( artifact);    
    for ( Iterator<ArtifactRepository> repo = remoteArtifactRepositories.iterator(); repo.hasNext(); ){
        ArtifactRepository repository = repo.next();            
        ArtifactRepositoryPolicy policy = 
                metadata.isSnapshot() ? repository.getSnapshots() : repository.getReleases();
        File file = new File( localRepository.getBasedir(), 
                localRepository.pathOfLocalRepositoryMetadata( metadata, repository ) );
        getLog().info("Updating " + repository.getBasedir());            
        try {
            wagonManager.getArtifactMetadata( metadata, repository, file, policy.getChecksumPolicy());
            getLog().info("Updated...");
        } catch (TransferFailedException e) {
            getLog().info("Couldn't find " +  metadata + " from repository: " + repository.getId() +
                    "\n Reason\n: " + e.getMessage() );
            e.printStackTrace();
        } catch (ResourceDoesNotExistException e) {
            getLog().info("Cannot find " +  metadata + " in repository: " + repository.getId() );
            if ( file.exists() ){
                file.delete();
            }
            e.printStackTrace();
        }
    }
}