revapi-maven-utils/src/main/java/org/revapi/maven/utils/ArtifactResolver.java
/**
     * Tries to find the newest version of the artifact that matches given regular expression.
     * The found version will be older than the {@code upToVersion} or newest available if {@code upToVersion} is null.
     *
     * @param gav the coordinates of the artifact. The version part is ignored
     * @param upToVersion the version up to which the versions will be matched
     * @param versionMatcher the matcher to match the version
     * @param remoteOnly true if only remotely available artifacts should be considered
     * @param upToInclusive whether the {@code upToVersion} should be considered inclusive or exclusive
     * @return the resolved artifact
     * @throws VersionRangeResolutionException
     */
Tries to find the newest version of the artifact that matches given regular expression.
The found version will be older than the  upToVersion or newest available if  upToVersion is null.

@param gav the coordinates of the artifact.
Tries to find the newest version of the artifact that matches given regular expression . The found version will be older than the upToVersion or newest available if upToVersion is null . @param gav the coordinates of the artifact .
public Artifact resolveNewestMatching(String gav, @Nullable String upToVersion, Pattern versionMatcher,
                                          boolean remoteOnly, boolean upToInclusive)
            throws VersionRangeResolutionException, ArtifactResolutionException {
        Artifact artifact = new DefaultArtifact(gav);
        artifact = artifact.setVersion(upToVersion == null ? "[,)" : "[," + upToVersion + (upToInclusive ? "]" : ")"));
        VersionRangeRequest rangeRequest = new VersionRangeRequest(artifact, repositories, null);
        RepositorySystemSession session = remoteOnly ? makeRemoteOnly(this.session) : this.session;
        VersionRangeResult result = repositorySystem.resolveVersionRange(session, rangeRequest);
        List<Version> versions = new ArrayList<>(result.getVersions());
        Collections.reverse(versions);
        for(Version v : versions) {
            if (versionMatcher.matcher(v.toString()).matches()) {
                return resolveArtifact(artifact.setVersion(v.toString()), session);
            }
        }
        throw new VersionRangeResolutionException(result) {
            @Override
            public String getMessage() {
                return "Failed to find a version of artifact '" + gav + "' that would correspond to an expression '"
                        + versionMatcher + "'. The versions found were: " + versions;
            }
        };
    }
public Artifact resolveNewestMatching ( String gav , @ Nullable String upToVersion , Pattern versionMatcher , boolean remoteOnly , boolean upToInclusive ) throws VersionRangeResolutionException , ArtifactResolutionException { Artifact artifact = new DefaultArtifact ( gav ) ; artifact = artifact . setVersion ( upToVersion == null ? "[,)" : "[," + upToVersion + ( upToInclusive ? "]" : ")" ) ) ; VersionRangeRequest rangeRequest = new VersionRangeRequest ( artifact , repositories , null ) ; RepositorySystemSession session = remoteOnly ? makeRemoteOnly ( this . session ) : this . session ; VersionRangeResult result = repositorySystem . resolveVersionRange ( session , rangeRequest ) ; List < Version > versions = new ArrayList < > ( result . getVersions ( ) ) ; Collections . reverse ( versions ) ; for ( Version v : versions ) { if ( versionMatcher . matcher ( v . toString ( ) ) . matches ( ) ) { return resolveArtifact ( artifact . setVersion ( v . toString ( ) ) , session ) ; } } throw new VersionRangeResolutionException ( result ) { @ Override public String getMessage ( ) { return "Failed to find a version of artifact '" + gav + "' that would correspond to an expression '" + versionMatcher + "'. The versions found were: " + versions ; } } ; }
Tries to find the newest version of the artifact that matches given regular expression.
Tries to find the newest version of the artifact that matches given regular expression .