5555import org .eclipse .aether .deployment .DeploymentException ;
5656import org .eclipse .aether .repository .RemoteRepository ;
5757import org .eclipse .aether .util .artifact .SubArtifact ;
58+ import org .slf4j .Logger ;
59+ import org .slf4j .LoggerFactory ;
5860
5961/**
6062 * Installs the artifact in the remote repository.
6365 */
6466@ Mojo (name = "deploy-file" , requiresProject = false , threadSafe = true )
6567public class DeployFileMojo extends AbstractDeployMojo {
68+ private final Logger log = LoggerFactory .getLogger (getClass ());
6669 /**
6770 * GroupId of the artifact to be deployed. Retrieved from POM file if specified.
6871 */
@@ -90,6 +93,15 @@ public class DeployFileMojo extends AbstractDeployMojo {
9093 @ Parameter (property = "packaging" )
9194 private String packaging ;
9295
96+ /**
97+ * Extension of the artifact to be deployed. If set, will override plugin own logic to detect extension. If not set,
98+ * as Maven expected, packaging determines the artifact extension.
99+ *
100+ * @since 3.1.3
101+ */
102+ @ Parameter (property = "extension" )
103+ private String extension ;
104+
93105 /**
94106 * Description passed to a generated POM file (in case of generatePom=true)
95107 */
@@ -196,7 +208,7 @@ void initProperties() throws MojoExecutionException {
196208 JarEntry entry = jarEntries .nextElement ();
197209
198210 if (pomEntry .matcher (entry .getName ()).matches ()) {
199- getLog () .debug ("Using " + entry .getName () + " as pomFile" );
211+ log .debug ("Using {} as pomFile" , entry .getName ());
200212 foundPom = true ;
201213 String base = file .getName ();
202214 if (base .indexOf ('.' ) > 0 ) {
@@ -215,7 +227,7 @@ void initProperties() throws MojoExecutionException {
215227 }
216228
217229 if (!foundPom ) {
218- getLog () .info ("pom.xml not found in " + file .getName ());
230+ log .info ("pom.xml not found in {}" , file .getName ());
219231 }
220232 } catch (IOException e ) {
221233 // ignore, artifact not packaged by Maven
@@ -235,7 +247,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
235247 if (Boolean .parseBoolean (skip )
236248 || ("releases" .equals (skip ) && !ArtifactUtils .isSnapshot (version ))
237249 || ("snapshots" .equals (skip ) && ArtifactUtils .isSnapshot (version ))) {
238- getLog () .info ("Skipping artifact deployment" );
250+ log .info ("Skipping artifact deployment" );
239251 return ;
240252 }
241253
@@ -266,18 +278,29 @@ public void execute() throws MojoExecutionException, MojoFailureException {
266278 DeployRequest deployRequest = new DeployRequest ();
267279 deployRequest .setRepository (remoteRepository );
268280
269- boolean isFilePom = classifier == null && "pom" .equals (packaging );
270- if (!isFilePom ) {
281+ String mainArtifactExtension ;
282+ if (classifier == null && "pom" .equals (packaging )) {
283+ mainArtifactExtension = "pom" ;
284+ } else {
271285 ArtifactType artifactType =
272286 session .getRepositorySession ().getArtifactTypeRegistry ().get (packaging );
273- if (artifactType != null
274- && (classifier == null || classifier .isEmpty ())
275- && !StringUtils .isEmpty (artifactType .getClassifier ())) {
276- classifier = artifactType .getClassifier ();
287+ if (artifactType != null ) {
288+ if (StringUtils .isEmpty (classifier ) && !StringUtils .isEmpty (artifactType .getClassifier ())) {
289+ classifier = artifactType .getClassifier ();
290+ }
291+ mainArtifactExtension = artifactType .getExtension ();
292+ } else {
293+ mainArtifactExtension = packaging ;
277294 }
278295 }
296+ if (extension != null && !Objects .equals (extension , mainArtifactExtension )) {
297+ log .warn (
298+ "Main artifact extension should be '{}' but was overridden to '{}'" ,
299+ mainArtifactExtension ,
300+ extension );
301+ }
279302 Artifact mainArtifact = new DefaultArtifact (
280- groupId , artifactId , classifier , isFilePom ? "pom" : getExtension ( file ) , version )
303+ groupId , artifactId , classifier , extension != null ? extension : mainArtifactExtension , version )
281304 .setFile (file );
282305 deployRequest .addArtifact (mainArtifact );
283306
@@ -293,10 +316,10 @@ public void execute() throws MojoExecutionException, MojoFailureException {
293316 deployRequest .addArtifact (new SubArtifact (mainArtifact , "" , "pom" , pomFile ));
294317 } else if (generatePom ) {
295318 temporaryPom = generatePomFile ();
296- getLog () .debug ("Deploying generated POM" );
319+ log .debug ("Deploying generated POM" );
297320 deployRequest .addArtifact (new SubArtifact (mainArtifact , "" , "pom" , temporaryPom ));
298321 } else {
299- getLog () .debug ("Skipping deploying POM" );
322+ log .debug ("Skipping deploying POM" );
300323 }
301324 }
302325
0 commit comments