gnodet commented on code in PR #466:
URL: 
https://github.com/apache/maven-install-plugin/pull/466#discussion_r4235493849


##########
src/main/java/org/apache/maven/plugins/install/InstallMojo.java:
##########
@@ -260,13 +261,14 @@ private ArtifactInstallerRequest processProject(Project 
project) {
                                 "The packaging for this project did not assign 
a file to the build artifact");
                     } else {
                         if (allowIncompleteProjects) {
-                            getLog().warn("");
-                            getLog().warn("The packaging plugin for this 
project did not assign");
-                            getLog().warn(
-                                            "a main file to the project but it 
has attachments. Change packaging to 'pom'.");
-                            getLog().warn("");
-                            getLog().warn("Incomplete projects like this will 
fail in future Maven versions!");
-                            getLog().warn("");
+                            // The main artifact has no file: its path is e.g. 
the output directory of a module
+                            // source hierarchy, where the JAR plugin attaches 
one JAR per Java module instead of
+                            // assigning a single main JAR. Install the POM 
and the attachments only; do not hand
+                            // the directory to the installer, which would 
otherwise fail with "is a folder".
+                            getLog().info("The project's main artifact has no 
file"
+                                    + " (e.g. a module source hierarchy 
produces one artifact per Java module);"
+                                    + " installing the POM and the attached 
artifacts only.");
+                            toInstall.remove(installable);
                         } else {
                             throw new MojoException("The packaging plugin for 
this project did not assign "
                                     + "a main file to the project but it has 
attachments. Change packaging to 'pom'.");

Review Comment:
   ```suggestion
                       } else if (usesModuleSourceHierarchy(project, 
projectManager)) {
                           getLog().info("Module source hierarchy: no main 
artifact produced;"
                                   + " installing POM and per-module artifacts 
only.");
                           toInstall.remove(installable);
                       } else if (allowIncompleteProjects) {
                           getLog().warn("");
                           getLog().warn("The packaging plugin for this project 
did not assign");
                           getLog().warn(
                                           "a main file to the project but it 
has attachments. Change packaging to 'pom'.");
                           getLog().warn("");
                           getLog().warn("Incomplete projects like this will 
fail in future Maven versions!");
                           getLog().warn("");
                           toInstall.remove(installable);
                       } else {
                           throw new MojoException("The packaging plugin for 
this project did not assign "
                                   + "a main file to the project but it has 
attachments. Change packaging to 'pom'.");
   ```
   Flattens the nested `if/else` into a chain with **module source hierarchy 
first** (auto-detected, no flag), then `allowIncompleteProjects` (preserved for 
other edge cases), then error. Also adds `toInstall.remove(installable)` in the 
`allowIncompleteProjects` branch (the original PR only removes it in the 
module-hierarchy branch).
   
   Needs a helper method added to the class:
   ```java
   private static boolean usesModuleSourceHierarchy(Project project, 
ProjectManager projectManager) {
       return projectManager.getSourceRoots(project).stream()
               .anyMatch(sr -> sr.module().isPresent());
   }
   ```



-- 
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