MavenSnapshotVersionValidator implements MavenVersionValidator { @Override public void validate(Repository repository, ArtifactCoordinates coordinates) throws VersionValidationException { String version = coordinates.getVersion(); if (isSnapshot(version) && !repository.acceptsSnapshots()) { throw new VersionValidationException("Cannot deploy a SNAPSHOT artifact to a repository with a release policy!"); } if (!isSnapshot(version) && repository.acceptsSnapshots() && !repository.acceptsReleases()) { throw new VersionValidationException("Cannot deploy a release artifact to a repository with a SNAPSHOT policy!"); } }  @PostConstruct @Override void register(); @Override String getAlias(); @Override String getDescription(); @Override boolean supports(Repository repository); @Override void validate(Repository repository,
                         ArtifactCoordinates coordinates); static final String ALIAS; static final String DESCRIPTION; }
@ExtendWith({ RepositoryManagementTestExecutionListener.class, ArtifactManagementTestExecutionListener.class }) @Test public void testSnapshotValidation(@MavenRepository(repositoryId = REPOSITORY_ID_2, policy = SNAPSHOT) Repository repository, @MavenTestArtifact(repositoryId = REPOSITORY_ID_2, id = GROUP_ID + ":" + ARTIFACT_ID, versions = { "1.0-SNAPSHOT", "1.0-20131004.115330-1", "1.0.8-20151025.032208-1", "1.0.8-alpha-1-20151025.032208-1"}) List<Path> validArtifactPaths) throws VersionValidationException, IOException { for (Path validArtifactPath : validArtifactPaths) { RepositoryPath repositoryPath = (RepositoryPath) validArtifactPath.normalize(); ArtifactCoordinates coordinates = RepositoryFiles.readCoordinates(repositoryPath); validator.validate(repository, coordinates); } }
@ExtendWith({ RepositoryManagementTestExecutionListener.class, ArtifactManagementTestExecutionListener.class }) @Test public void testInvalidArtifacts(@MavenRepository(repositoryId = REPOSITORY_ID_3, policy = SNAPSHOT) Repository repository, @MavenTestArtifact(repositoryId = REPOSITORY_ID_3, id = GROUP_ID + ":" + ARTIFACT_ID, versions = { "1", "1.0", "1.0.1", "1.0.1-alpha" }) List<Path> invalidArtifactPaths) throws IOException { for (Path invalidArtifactPath : invalidArtifactPaths) { RepositoryPath repositoryPath = (RepositoryPath) invalidArtifactPath.normalize(); ArtifactCoordinates coordinates = RepositoryFiles.readCoordinates(repositoryPath); try { validator.validate(repository, coordinates); fail("Incorrectly validated artifact with version " + coordinates.getVersion()); } catch (VersionValidationException e) { } } }