diff --git a/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionResolver.java b/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionResolver.java index b33728be21..d0058cb91d 100644 --- a/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionResolver.java +++ b/maven-aether-provider/src/main/java/org/apache/maven/repository/internal/DefaultVersionResolver.java @@ -36,9 +36,11 @@ import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.StringUtils; +import org.sonatype.aether.ConfigurationProperties; import org.sonatype.aether.RepositoryCache; import org.sonatype.aether.RepositoryListener; import org.sonatype.aether.RepositorySystemSession; +import org.sonatype.aether.util.artifact.SubArtifact; import org.sonatype.aether.util.listener.DefaultRepositoryEvent; import org.sonatype.aether.util.metadata.DefaultMetadata; import org.sonatype.aether.artifact.Artifact; @@ -116,7 +118,7 @@ public class DefaultVersionResolver Key cacheKey = null; RepositoryCache cache = session.getCache(); - if ( cache != null ) + if ( cache != null && !ConfigurationProperties.get( session, "aether.versionResolver.noCache", false ) ) { cacheKey = new Key( session, request ); @@ -248,7 +250,7 @@ public class DefaultVersionResolver } } - if ( cacheKey != null && metadata != null ) + if ( cacheKey != null && metadata != null && isSafelyCacheable( session, artifact ) ) { cache.put( session, cacheKey, new Record( result.getVersion(), result.getRepository() ) ); } @@ -365,6 +367,28 @@ public class DefaultVersionResolver return StringUtils.clean( classifier ) + ':' + StringUtils.clean( extension ); } + private boolean isSafelyCacheable( RepositorySystemSession session, Artifact artifact ) + { + /* + * The workspace/reactor is in flux so we better not assume definitive information for any of its + * artifacts/projects. + */ + + WorkspaceReader workspace = session.getWorkspaceReader(); + if ( workspace == null ) + { + return true; + } + + Artifact pomArtifact = artifact; + if ( pomArtifact.getClassifier().length() > 0 || !"pom".equals( pomArtifact.getExtension() ) ) + { + pomArtifact = new SubArtifact( artifact, "", "pom" ); + } + + return workspace.findArtifact( pomArtifact ) == null; + } + private static class VersionInfo { diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectDependenciesResolver.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectDependenciesResolver.java index 515f7c86f8..3bb5aa2ad9 100644 --- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectDependenciesResolver.java +++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectDependenciesResolver.java @@ -96,7 +96,9 @@ public class DefaultProjectDependenciesResolver if ( !JavaScopes.SYSTEM.equals( dep.getScope() ) && dep.getArtifact().getFile() != null ) { // enable re-resolution - dep = dep.setArtifact( dep.getArtifact().setFile( null ) ); + org.sonatype.aether.artifact.Artifact art = dep.getArtifact(); + art = art.setFile( null ).setVersion( art.getBaseVersion() ); + dep = dep.setArtifact( art ); } collect.addDependency( dep ); }