[ https://issues.apache.org/jira/browse/MPLUGIN-450?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17786035#comment-17786035 ]
ASF GitHub Bot commented on MPLUGIN-450: ---------------------------------------- michael-o commented on code in PR #240: URL: https://github.com/apache/maven-plugin-tools/pull/240#discussion_r1393124464 ########## maven-plugin-plugin/src/main/java/org/apache/maven/plugin/plugin/AbstractGeneratorMojo.java: ########## @@ -81,28 +80,24 @@ public void execute() throws MojoExecutionException { return; } - String defaultGoalPrefix = getDefaultGoalPrefix(project); - - if (goalPrefix == null) { - goalPrefix = defaultGoalPrefix; - } else if (!goalPrefix.equals(defaultGoalPrefix)) { - getLog().warn(LS + LS + "Goal prefix is specified as: '" + goalPrefix + "'. " - + "Maven currently expects it to be '" + defaultGoalPrefix + "'." + LS); + if (goalPrefix == null || goalPrefix.isEmpty()) { + goalPrefix = getDefaultGoalPrefix(project); + } + if (goalPrefix == null || goalPrefix.isEmpty()) { + throw new MojoExecutionException("You need to specify a goalPrefix as it can not be correctly computed"); } generate(); } static String getDefaultGoalPrefix(MavenProject project) { - String defaultGoalPrefix; - if ("maven-plugin-report-plugin".equalsIgnoreCase(project.getArtifactId())) { - defaultGoalPrefix = "plugin-report"; - } else if ("maven-plugin".equalsIgnoreCase(project.getArtifactId())) { - defaultGoalPrefix = - project.getGroupId().substring(project.getGroupId().lastIndexOf('.') + 1); + String artifactId = project.getArtifactId(); + if (artifactId.endsWith("-maven-plugin")) { + return artifactId.substring(0, artifactId.length() - "-maven-plugin".length()); + } else if (artifactId.startsWith("maven-") && artifactId.endsWith("-plugin")) { + return artifactId.substring("maven-".length(), artifactId.length() - "-plugin".length()); } else { - defaultGoalPrefix = PluginDescriptor.getGoalPrefixFromArtifactId(project.getArtifactId()); Review Comment: Alright, then not worth it. > Make goal prefix mandatory by default > ------------------------------------- > > Key: MPLUGIN-450 > URL: https://issues.apache.org/jira/browse/MPLUGIN-450 > Project: Maven Plugin Tools > Issue Type: Improvement > Components: Plugin Plugin > Reporter: Tamas Cservenak > Priority: Major > > The goal prefix currently is not mandatory, and plugin uses heuristic to > figure it out, if possible (xxx-maven-plugin or maven-xxx-plugin, latter for > org.apache.maven plugins ONLY). > In general, goal prefix is optional, but "good to have", and usually is > present. > Cases when is not present, is when heuristics fails (so plugin module is not > named as "xxx-maven-plugin" or "maven-xxx-plugin") and user did not provide > one either. The cases when prefix is not present is mostly unintentional, but > maven-plugin-plugin leaves this without any remark or warning. > IMHO, the maven-plugin-plugin should either warn, or even fail the build in > case when goal prefix is not present, but we may want to have some option to > turn off this feature (for me unknown reasons, where it would be expected to > NOT have goal prefix for a reason). > TL;DR Am pretty much sure that in most of the cases when plugin developer > ends up with plugin without prefix, that it was unintentional (and causes > surprise later, not to mention refactoring the module name or POM change to > configure it), while there MAY be cases where goal prefix is not desired for > some reason (ie. plugin not mentioned for manual/CLI invocation). Simply put, > the out of the box defaults should enforce presence of it, while advanced > users still can produce prefix-less plugins with some extra configuration. > This would make things more explicit as well: even if plugin is named as > xxx-maven-plugin, configuration would be clear I do not want prefix for it. -- This message was sent by Atlassian Jira (v8.20.10#820010)