@@ -88,27 +88,6 @@ public SonatypeService(RestTemplateBuilder builder, SonatypeProperties sonatypeP
8888 this .artifactCollector = new ArtifactCollector (sonatypeProperties .getExclude ());
8989 }
9090
91- /**
92- * Checks if artifacts are already published to Maven Central.
93- * @return true if artifacts are published
94- * @param releaseInfo the release information
95- */
96- public boolean artifactsPublished (ReleaseInfo releaseInfo ) {
97- try {
98- ResponseEntity <?> entity = this .restTemplate
99- .getForEntity (String .format (NEXUS_REPOSITORY_PATH + "%s/spring-boot-%s.jar.sha1" ,
100- releaseInfo .getVersion (), releaseInfo .getVersion ()), byte [].class );
101- if (HttpStatus .OK .equals (entity .getStatusCode ())) {
102- logger .info ("Already published to Sonatype." );
103- return true ;
104- }
105- }
106- catch (HttpClientErrorException ex ) {
107-
108- }
109- return false ;
110- }
111-
11291 /**
11392 * Publishes the release by creating a staging repository and deploying to it the
11493 * artifacts at the given {@code artifactsRoot}. The repository is then closed and,
@@ -117,6 +96,9 @@ public boolean artifactsPublished(ReleaseInfo releaseInfo) {
11796 * @param artifactsRoot the root directory of the artifacts to stage
11897 */
11998 public void publish (ReleaseInfo releaseInfo , Path artifactsRoot ) {
99+ if (artifactsPublished (releaseInfo )) {
100+ return ;
101+ }
120102 logger .info ("Creating staging repository" );
121103 String buildId = releaseInfo .getBuildNumber ();
122104 String repositoryId = createStagingRepository (buildId );
@@ -130,6 +112,22 @@ public void publish(ReleaseInfo releaseInfo, Path artifactsRoot) {
130112 logger .info ("Staging repository released" );
131113 }
132114
115+ private boolean artifactsPublished (ReleaseInfo releaseInfo ) {
116+ try {
117+ ResponseEntity <?> entity = this .restTemplate
118+ .getForEntity (String .format (NEXUS_REPOSITORY_PATH + "%s/spring-boot-%s.jar.sha1" ,
119+ releaseInfo .getVersion (), releaseInfo .getVersion ()), byte [].class );
120+ if (HttpStatus .OK .equals (entity .getStatusCode ())) {
121+ logger .info ("Already published to Sonatype." );
122+ return true ;
123+ }
124+ }
125+ catch (HttpClientErrorException ex ) {
126+
127+ }
128+ return false ;
129+ }
130+
133131 private String createStagingRepository (String buildId ) {
134132 Map <String , Object > body = new HashMap <>();
135133 body .put ("data" , Collections .singletonMap ("description" , buildId ));
0 commit comments