Skip to content

Commit

Permalink
Use "common ground" for Maven3 and Maven4
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed Jun 4, 2024
1 parent 2fb1877 commit e90b4b5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/it/MNG-8137/verify.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
*/

String log = new File(basedir, 'build.log').text
assert log.contains('[WARNING] Language of project is \'none\', this is most probably not what you want')
assert log.contains('[WARNING] The project packaging language is NOT \'java\'; this is most probably not what you want')
19 changes: 10 additions & 9 deletions src/main/java/org/apache/maven/plugins/jar/AbstractJarMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@
import java.nio.file.FileSystems;
import java.util.Arrays;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

import org.apache.maven.archiver.MavenArchiveConfiguration;
import org.apache.maven.archiver.MavenArchiver;
import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.handler.manager.ArtifactHandlerManager;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
Expand Down Expand Up @@ -132,8 +131,8 @@ public abstract class AbstractJarMojo extends AbstractMojo {
@Component
private MavenProjectHelper projectHelper;

@Component(hint = "pom")
private ArtifactHandler pomArtifactHandler;
@Component
private ArtifactHandlerManager artifactHandlerManager;

/**
* Require the jar plugin to build a new JAR even if none of the contents appear to have changed. By default, this
Expand Down Expand Up @@ -356,11 +355,13 @@ public void execute() throws MojoExecutionException {
throw new MojoExecutionException("You have to use a classifier "
+ "to attach supplemental artifacts to the project instead of replacing them.");
}
if (Objects.equals(
pomArtifactHandler.getLanguage(),
getProject().getArtifact().getArtifactHandler().getLanguage())) {
getLog().warn("Language of project is '" + pomArtifactHandler.getLanguage()
+ "', this is most probably not what you want");

if (!"java"
.equals(artifactHandlerManager
.getArtifactHandler(getProject().getPackaging())
.getLanguage())) {
getLog().warn(
"The project packaging language is NOT 'java'; this is most probably not what you want");
}
getProject().getArtifact().setFile(jarFile);
}
Expand Down

0 comments on commit e90b4b5

Please sign in to comment.