2323import org .gradle .api .publish .PublishingExtension ;
2424import org .gradle .api .publish .maven .MavenPom ;
2525import org .gradle .api .publish .maven .MavenPublication ;
26- import org .gradle .api .publish .maven .tasks .PublishToMavenRepository ;
2726
2827import java .io .File ;
29- import java .net .URL ;
3028
3129import static org .eclipse .edc .plugins .edcbuild .conventions .ConventionFunctions .requireExtension ;
32- import static org .gradle .api .artifacts .ArtifactRepositoryContainer .MAVEN_CENTRAL_URL ;
3330
3431/**
3532 * Configures the Maven POM for each project:
@@ -49,14 +46,9 @@ public void apply(Project target) {
4946 var pomExt = requireExtension (project , BuildExtension .class ).getPom ();
5047
5148 pubExt .getPublications ().stream ()
52- .filter (MavenPublication . class :: isInstance )
53- .map (MavenPublication . class :: cast )
49+ .filter (p -> p instanceof MavenPublication )
50+ .map (p -> ( MavenPublication ) p )
5451 .peek (mavenPub -> mavenPub .pom (pom -> setPomInformation (pomExt , target , pom )))
55- .peek (publication -> {
56- if (!publication .getVersion ().endsWith ("-SNAPSHOT" )) {
57- disablePublishIfArtifactAlreadyUploaded (publication , project );
58- }
59- })
6052 .forEach (mavenPub -> {
6153 var openapiFiles = target .getLayout ().getBuildDirectory ().getAsFile ().get ().toPath ()
6254 .resolve ("docs" ).resolve ("openapi" ).toFile ()
@@ -76,24 +68,6 @@ public void apply(Project target) {
7668 });
7769 }
7870
79- private void disablePublishIfArtifactAlreadyUploaded (MavenPublication publication , Project project ) {
80- project .getTasks ().withType (PublishToMavenRepository .class ).forEach (task -> {
81- var artifact = publication .getGroupId () + ":" + publication .getArtifactId () + ":" + publication .getVersion ();
82-
83- try {
84- var artifactPath = MAVEN_CENTRAL_URL + publication .getGroupId ().replace ('.' , '/' ) +
85- "/" + publication .getArtifactId () + "/" + publication .getVersion () +
86- "/" + publication .getArtifactId () + "-" + publication .getVersion () + ".pom" ;
87-
88- new URL (artifactPath ).openStream ().close ();
89- project .getLogger ().debug ("Artifact {} already exists - skipping publish" , artifact );
90- task .setEnabled (false );
91- } catch (Throwable e ) {
92- project .getLogger ().debug ("Artifact {} not found on maven central - will publish" , artifact );
93- }
94- });
95- }
96-
9771 private String getFilenameWithoutExtension (File openapiFile ) {
9872 return openapiFile .getName ().substring (0 , openapiFile .getName ().lastIndexOf ("." ));
9973 }
0 commit comments