Index: src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java =================================================================== --- src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java (revision 619465) +++ src/main/java/org/apache/maven/artifact/resolver/DefaultArtifactCollector.java (working copy) @@ -262,85 +262,102 @@ Artifact artifact = child.getArtifact(); try { - if ( artifact.getVersion() == null ) - { - // set the recommended version - // TODO: maybe its better to just pass the range through to retrieval and use a transformation? - ArtifactVersion version; - if ( !artifact.isSelectedVersionKnown() ) + + boolean done = false; + ResolutionGroup rGroup = null; + + while (!done) { + + if ( artifact.getVersion() == null ) { - List versions = artifact.getAvailableVersions(); - if ( versions == null ) + // set the recommended version + // TODO: maybe its better to just pass the range through to retrieval and use a transformation? + ArtifactVersion version; + if ( !artifact.isSelectedVersionKnown() ) { - versions = source.retrieveAvailableVersions( artifact, localRepository, - remoteRepositories ); - artifact.setAvailableVersions( versions ); + List versions = artifact.getAvailableVersions(); + if ( versions == null ) + { + versions = source.retrieveAvailableVersions( artifact, localRepository, + remoteRepositories ); + artifact.setAvailableVersions( versions ); + } + + VersionRange versionRange = artifact.getVersionRange(); + + version = versionRange.matchVersion( versions ); + + if ( version == null ) + { + if ( versions.isEmpty() ) + { + throw new OverConstrainedVersionException( + "No versions are present in the repository for the artifact with a range " + + versionRange, artifact, remoteRepositories ); + } + else + { + throw new OverConstrainedVersionException( "Couldn't find a version in " + + versions + " to match range " + versionRange, artifact, + remoteRepositories ); + } + } } - - VersionRange versionRange = artifact.getVersionRange(); - - version = versionRange.matchVersion( versions ); - - if ( version == null ) + else { - if ( versions.isEmpty() ) + version = artifact.getSelectedVersion(); + } + + artifact.selectVersion( version.toString() ); + fireEvent( ResolutionListener.SELECT_VERSION_FROM_RANGE, listeners, child ); + } + + Object childKey = child.getKey(); + if ( managedVersions.containsKey( childKey ) ) + { + // If this child node is a managed dependency, ensure + // we are using the dependency management version + // of this child if applicable b/c we want to use the + // managed version's POM, *not* any other version's POM. + // We retrieve the POM below in the retrieval step. + manageArtifact( child, managedVersions, listeners ); + + // Also, we need to ensure that any exclusions it presents are + // added to the artifact before we retrive the metadata + // for the artifact; otherwise we may end up with unwanted + // dependencies. + Artifact ma = (Artifact) managedVersions.get( childKey ); + ArtifactFilter managedExclusionFilter = ma.getDependencyFilter(); + if ( null != managedExclusionFilter ) + { + if ( null != artifact.getDependencyFilter() ) { - throw new OverConstrainedVersionException( - "No versions are present in the repository for the artifact with a range " + - versionRange, artifact, remoteRepositories ); + AndArtifactFilter aaf = new AndArtifactFilter(); + aaf.add( artifact.getDependencyFilter() ); + aaf.add( managedExclusionFilter ); + artifact.setDependencyFilter( aaf ); } else { - throw new OverConstrainedVersionException( "Couldn't find a version in " + - versions + " to match range " + versionRange, artifact, - remoteRepositories ); + artifact.setDependencyFilter( managedExclusionFilter ); } } } - else - { - version = artifact.getSelectedVersion(); - } - - artifact.selectVersion( version.toString() ); - fireEvent( ResolutionListener.SELECT_VERSION_FROM_RANGE, listeners, child ); - } - - Object childKey = child.getKey(); - if ( managedVersions.containsKey( childKey ) ) - { - // If this child node is a managed dependency, ensure - // we are using the dependency management version - // of this child if applicable b/c we want to use the - // managed version's POM, *not* any other version's POM. - // We retrieve the POM below in the retrieval step. - manageArtifact( child, managedVersions, listeners ); + + artifact.setDependencyTrail( node.getDependencyTrail() ); - // Also, we need to ensure that any exclusions it presents are - // added to the artifact before we retrive the metadata - // for the artifact; otherwise we may end up with unwanted - // dependencies. - Artifact ma = (Artifact) managedVersions.get( childKey ); - ArtifactFilter managedExclusionFilter = ma.getDependencyFilter(); - if ( null != managedExclusionFilter ) - { - if ( null != artifact.getDependencyFilter() ) - { - AndArtifactFilter aaf = new AndArtifactFilter(); - aaf.add( artifact.getDependencyFilter() ); - aaf.add( managedExclusionFilter ); - artifact.setDependencyFilter( aaf ); - } - else - { - artifact.setDependencyFilter( managedExclusionFilter ); - } - } + String originalGroupId = artifact.getGroupId(); + String originalArtifactId = artifact.getArtifactId(); + VersionRange originalVersionRange = artifact.getVersionRange(); + + rGroup = source.retrieve( artifact, localRepository, remoteRepositories ); + + done = artifact.getGroupId().equals(originalGroupId) + && artifact.getArtifactId().equals(originalArtifactId) + && artifact.getVersionRange().equals(originalVersionRange); } + - artifact.setDependencyTrail( node.getDependencyTrail() ); - ResolutionGroup rGroup = source.retrieve( artifact, localRepository, remoteRepositories ); - //TODO might be better to have source.retreive() throw a specific exception for this situation //and catch here rather than have it return null if ( rGroup == null )