bmarwell commented on code in PR #621:
URL: 
https://github.com/apache/maven-jlink-plugin/pull/621#discussion_r2386279338


##########
src/main/java/org/apache/maven/plugins/jlink/JLinkMojo.java:
##########
@@ -453,14 +461,16 @@ public void execute() throws MojoExecutionException, 
MojoFailureException {
 
         File createZipArchiveFromImage = 
createZipArchiveFromImage(buildDirectory, outputDirectoryImage);
 
-        if (hasClassifier()) {
-            projectHelper.attachArtifact(getProject(), "jlink", 
getClassifier(), createZipArchiveFromImage);
-        } else {
-            if (projectHasAlreadySetAnArtifact()) {
-                throw new MojoExecutionException("You have to use a classifier 
"
-                        + "to attach supplemental artifacts to the project 
instead of replacing them.");
+        if (attach) {
+            if (hasClassifier()) {
+                projectHelper.attachArtifact(getProject(), "jlink", 
getClassifier(), createZipArchiveFromImage);
+            } else {
+                if (projectHasAlreadySetAnArtifact()) {
+                    throw new MojoExecutionException("You have to use a 
classifier "
+                            + "to attach supplemental artifacts to the project 
instead of replacing them.");
+                }
+                getProject().getArtifact().setFile(createZipArchiveFromImage);
             }
-            getProject().getArtifact().setFile(createZipArchiveFromImage);

Review Comment:
   I (personally) prefer guard statements. Move this block in it entirety into 
a method and then:
   
   ```java
   if (!attach) {
     return;
   ]
   
   if (hasClassifier()) {
     ... attach
     return;
   }
   
   if (projectHasAlreadySetAnArtifact()) {
     throw exception
   }
   
   project.artifact.file = createdZipArchiveFromImage
   ```
   
   I think this would be easier to maintain.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to