code: static Artifact resolveConstrained(MavenProject project, String gav, Pattern versionRegex,
              ArtifactResolver resolver)
              throws VersionRangeResolutionException, ArtifactResolutionException {
          boolean latest = gav.endsWith(":LATEST");
          if (latest || gav.endsWith(":RELEASE")) {
              Artifact a = new DefaultArtifact(gav);
  
              if (latest) {
                  versionRegex = versionRegex == null ? ANY : versionRegex;
              } else {
                  versionRegex = versionRegex == null ? ANY_NON_SNAPSHOT : versionRegex;
              }
  
              String upTo = project.getGroupId().equals(a.getGroupId()) && project.getArtifactId().equals(a.getArtifactId())
                      ? project.getVersion()
                      : null;
  
              return resolver.resolveNewestMatching(gav, upTo, versionRegex, latest, latest);
          } else {
              String projectGav = getProjectArtifactCoordinates(project, null);
              Artifact ret = null;
  
              if (projectGav.equals(gav)) {
                  ret = findProjectArtifact(project);
              }
  
              return ret == null ? resolver.resolveArtifact(gav) : ret;
          }
      }
docs: Resolves the gav using the resolver. If the gav corresponds to the project artifact and is an unresolved version
  for a RELEASE or LATEST, the gav is resolved such it a release not newer than the project version is found that
  optionally corresponds to the provided version regex, if provided.
  
  <p>If the gav exactly matches the current project, the file of the artifact is found on the filesystem in
  target directory and the resolver is ignored.
  
  @param project      the project to restrict by, if applicable
  @param gav          the gav to resolve
  @param versionRegex the optional regex the version must match to be considered.
  @param resolver     the version resolver to use
  @return the resolved artifact matching the criteria.
  @throws VersionRangeResolutionException on error
  @throws ArtifactResolutionException     on error