MavenDependencyFormatter implements DependencySynonymFormatter { @Override public String getDependencySnippet(ArtifactCoordinates artifactCoordinates) { MavenArtifactCoordinates coordinates = (MavenArtifactCoordinates) artifactCoordinates; String sb = "<dependency>\n" + " <groupId>" + coordinates.getGroupId() + "</groupId>\n" + " <artifactId>" + coordinates.getArtifactId() + "</artifactId>\n" + " <version>" + coordinates.getVersion() + "</version>\n" + " <type>" + coordinates.getExtension() + "</type>\n" + (coordinates.getClassifier() != null ? " <classifier>" + coordinates.getClassifier() + "</classifier>\n" : "" ) + " <scope>compile</scope>\n" + "</dependency>\n"; return sb; }  @PostConstruct @Override void register(); @Override String getLayout(); @Override String getFormatAlias(); @Override String getDependencySnippet(ArtifactCoordinates artifactCoordinates);  }
@ExtendWith({ RepositoryManagementTestExecutionListener.class, ArtifactManagementTestExecutionListener.class }) @Test public void testMavenDependencyGeneration(@MavenRepository(repositoryId = REPOSITORY_RELEASES, setup = MavenIndexedRepositorySetup.class) Repository repository, @MavenTestArtifact(repositoryId = REPOSITORY_RELEASES, id = GROUP_ID + ":" + ARTIFACT_ID, versions = { VERSION_1 }) Path artifactPath) throws ProviderImplementationException, IOException { DependencySynonymFormatter formatter = compatibleDependencyFormatRegistry.getProviderImplementation(Maven2LayoutProvider.ALIAS, Maven2LayoutProvider.ALIAS); assertThat(formatter).as("Failed to look up dependency synonym formatter!").isNotNull(); MavenArtifactCoordinates coordinates = (MavenArtifactCoordinates) RepositoryFiles.readCoordinates( (RepositoryPath) artifactPath.normalize()); String snippet = formatter.getDependencySnippet(coordinates); System.out.println(snippet); assertThat(snippet) .as("Failed to generate dependency!") .isEqualTo("<dependency>\n" + " <groupId>org.carlspring.strongbox</groupId>\n" + " <artifactId>maven-snippet</artifactId>\n" + " <version>1.0</version>\n" + " <type>jar</type>\n" + " <scope>compile</scope>\n" + "</dependency>\n"); }
@ExtendWith({ RepositoryManagementTestExecutionListener.class, ArtifactManagementTestExecutionListener.class }) @Test public void testMavenDependencyGenerationWithClassifier(@MavenRepository(repositoryId = REPOSITORY_RELEASES, setup = MavenIndexedRepositorySetup.class) Repository repository, @MavenArtifactWithClassifiers(repositoryId = REPOSITORY_RELEASES, id = GROUP_ID + ":" + ARTIFACT_ID, versions = { VERSION_2 }) Path artifactPath) throws ProviderImplementationException, IOException { DependencySynonymFormatter formatter = compatibleDependencyFormatRegistry.getProviderImplementation(Maven2LayoutProvider.ALIAS, Maven2LayoutProvider.ALIAS); assertThat(formatter).as("Failed to look up dependency synonym formatter!").isNotNull(); MavenArtifactCoordinates coordinates = (MavenArtifactCoordinates) RepositoryFiles.readCoordinates( (RepositoryPath) artifactPath.normalize()); coordinates.setClassifier(CLASSIFIER_SOURCES); String snippet = formatter.getDependencySnippet(coordinates); System.out.println(snippet); assertThat(snippet) .as("Failed to generate dependency!") .isEqualTo("<dependency>\n" + " <groupId>org.carlspring.strongbox</groupId>\n" + " <artifactId>maven-snippet</artifactId>\n" + " <version>2.0</version>\n" + " <type>jar</type>\n" + " <classifier>sources</classifier>\n" + " <scope>compile</scope>\n" + "</dependency>\n"); }