GradleDependencyFormatter implements DependencySynonymFormatter { @Override public String getDependencySnippet(ArtifactCoordinates artifactCoordinates) { MavenArtifactCoordinates coordinates = (MavenArtifactCoordinates) artifactCoordinates; return "compile \"" + coordinates.getGroupId() + ":" + coordinates.getArtifactId() + ":" + coordinates.getVersion() + (coordinates.getClassifier() != null ? ":" + coordinates.getClassifier() : "") + (coordinates.getExtension() != null && !coordinates.getExtension().equals("jar") ? "@" + coordinates.getExtension() : "") + "\"\n"; }  @PostConstruct @Override void register(); @Override String getLayout(); @Override String getFormatAlias(); @Override String getDependencySnippet(ArtifactCoordinates artifactCoordinates); static final String ALIAS; }
@Test public void testGradleDependencyGeneration() throws ProviderImplementationException { DependencySynonymFormatter formatter = compatibleDependencyFormatRegistry.getProviderImplementation(Maven2LayoutProvider.ALIAS, GradleDependencyFormatter.ALIAS); assertThat(formatter).as("Failed to look up dependency synonym formatter!").isNotNull(); MavenArtifactCoordinates coordinates = new MavenArtifactCoordinates(); coordinates.setGroupId("org.carlspring.strongbox"); coordinates.setArtifactId("maven-snippet"); coordinates.setVersion("1.0"); coordinates.setExtension("jar"); String snippet = formatter.getDependencySnippet(coordinates); System.out.print(snippet); assertThat(snippet) .as("Failed to generate dependency!") .isEqualTo("compile \"org.carlspring.strongbox:maven-snippet:1.0\"\n"); }
@Test public void testGradleDependencyGenerationWithClassifier() throws ProviderImplementationException { DependencySynonymFormatter formatter = compatibleDependencyFormatRegistry.getProviderImplementation(Maven2LayoutProvider.ALIAS, GradleDependencyFormatter.ALIAS); assertThat(formatter).as("Failed to look up dependency synonym formatter!").isNotNull(); MavenArtifactCoordinates coordinates = new MavenArtifactCoordinates(); coordinates.setGroupId("org.carlspring.strongbox"); coordinates.setArtifactId("maven-snippet"); coordinates.setVersion("1.0"); coordinates.setClassifier("jdk12"); String snippet = formatter.getDependencySnippet(coordinates); System.out.print(snippet); assertThat(snippet) .as("Failed to generate dependency!") .isEqualTo("compile \"org.carlspring.strongbox:maven-snippet:1.0:jdk12\"\n"); }
@Test public void testGradleDependencyGenerationWithExtensionAndClassifier() throws ProviderImplementationException { DependencySynonymFormatter formatter = compatibleDependencyFormatRegistry.getProviderImplementation(Maven2LayoutProvider.ALIAS, GradleDependencyFormatter.ALIAS); assertThat(formatter).as("Failed to look up dependency synonym formatter!").isNotNull(); MavenArtifactCoordinates coordinates = new MavenArtifactCoordinates(); coordinates.setGroupId("org.carlspring.strongbox"); coordinates.setArtifactId("maven-snippet"); coordinates.setVersion("1.0"); coordinates.setExtension("zip"); coordinates.setClassifier("jdk12"); String snippet = formatter.getDependencySnippet(coordinates); System.out.print(snippet); assertThat(snippet) .as("Failed to generate dependency!") .isEqualTo("compile \"org.carlspring.strongbox:maven-snippet:1.0:jdk12@zip\"\n"); }