ascheman commented on code in PR #11549:
URL: https://github.com/apache/maven/pull/11549#discussion_r2617956929
##########
impl/maven-core/src/main/java/org/apache/maven/internal/impl/DefaultProjectManager.java:
##########
@@ -119,15 +119,16 @@ public void attachArtifact(@Nonnull Project project,
@Nonnull ProducedArtifact a
artifact.getExtension(),
null);
}
- if (!Objects.equals(project.getGroupId(), artifact.getGroupId())
- || !Objects.equals(project.getArtifactId(),
artifact.getArtifactId())
- || !Objects.equals(
- project.getVersion(),
artifact.getBaseVersion().toString())) {
+ // Verify groupId and version, intentionally allow artifactId to
differ as a project may be multi-module.
+ String g1 = project.getGroupId();
+ String g2 = artifact.getGroupId();
+ String v1 = project.getVersion();
+ String v2 = artifact.getBaseVersion().toString();
+ if (!Objects.equals(g1, g2) || !Objects.equals(v1, v2)) {
throw new IllegalArgumentException(
- "The produced artifact must have the same
groupId/artifactId/version than the project it is attached to. Expecting "
- + project.getGroupId() + ":" +
project.getArtifactId() + ":" + project.getVersion()
- + " but received " + artifact.getGroupId() + ":" +
artifact.getArtifactId() + ":"
- + artifact.getBaseVersion());
+ "The produced artifact must have the same groupId and
version than the project it is attached to. Expecting "
Review Comment:
With Java 17 (pre-req for M4) we have multi line strings. I would think the
following would be even better readable:
```java
"""
The produced artifact must have the same groupId and version as the project
it is attached to. \
Expecting %s:%s:%s but received %s:%s:%s"""
.formatted(g1, project.getArtifactId(), v1, g2,
artifact.getArtifactId(), v2));
```
Unfortunately, Spotless reformats it a little bit (adding the `.format`
method call directly to the end of the String literal):
```java
"""
The produced artifact must have the same groupId and version as the project
it is attached to. \
Expecting %s:%s:%s but received %s:%s:%s""".formatted(g1,
project.getArtifactId(), v1, g2, artifact.getArtifactId(), v2));
```
Nevertheless, it's still multi-line and one can easier see how the final
message would look like.
Note that the \ enables to split the message into multiple lines in the IDE
but concatenates the lines in the final output.
What do you think?
--
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]