gnodet opened a new pull request, #613: URL: https://github.com/apache/maven-jar-plugin/pull/613
## Problem When `jar:jar` (or `jar:test-jar`) is invoked on a project whose packaging does not produce a main artifact (e.g. `<packaging>pom</packaging>`), the previous code unconditionally called `project.getMainArtifact().orElseThrow()`. On Maven 4, this throws a `NoSuchElementException` with no helpful message. The Maven 4 API documents this explicitly: > *This artifact MAY be absent if the project is actually not producing any main artifact (i.e. "pom" packaging).* This was originally reported as [MNG-8137](https://issues.apache.org/jira/browse/MNG-8137) and discussed in PR #89. ## Fix Add an early check at the start of `execute()`: if `project.getMainArtifact()` is empty, log a clear warning and return early without creating any JAR. The check uses the Maven 4 API correctly — instead of string-comparing packaging ids (which the API Javadoc explicitly discourages), we rely on `getMainArtifact().isEmpty()` as the canonical way to detect packagings that don't produce a main artifact. ## Changes - `AbstractJarMojo.execute()`: early-exit with a warning when the project has no main artifact - New integration test `MNG-8137-warn-pom-packaging`: verifies build succeeds, no JAR is created, and the warning is present in the log ## Notes This supersedes PR #89 which targeted the Maven 3 code path (using `ArtifactHandlerManager`). The current `master` branch uses the Maven 4 API exclusively, so the fix is simpler and more idiomatic. -- 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]
