Maven 2.x and 3.x GPG Plugin

NPE in GpgSigner

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.0-alpha-4
  • Fix Version/s: 1.0
  • Component/s: None
  • Labels:
    None
  • Number of attachments :
    0

Description

If I run "mvn package gpg:sign", this works. If I run "mvn gpg:sign", I get the following stack trace:

java.lang.NullPointerException
	at org.apache.maven.plugin.gpg.GpgSigner.generateSignatureForArtifact(GpgSigner.java:119)
	at org.apache.maven.plugin.gpg.GpgSignAttachedMojo.execute(GpgSignAttachedMojo.java:228)
	at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
	at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)

After running this through a debugger, I can see that this is because the 'file' object (project.getArtifact().getFile()) is null, which seems to be the case any time the artifact wasn't generated in this invocation of Maven. At the very least, this should result in a good error message, although it would be nice if "gpg:sign" would work on an artifact that was previously-generated.

Activity

Hide
Geoffrey Wiseman added a comment - - edited

This is the simplest patch I can imagine to improve the situation. It's not a very good solution, but it least explains the problem. A more workable solution would be to support signing previously-generated files, I would think.

### Eclipse Workspace Patch 1.0
#P maven-gpg-plugin
Index: src/main/java/org/apache/maven/plugin/gpg/GpgSignAttachedMojo.java
===================================================================
--- src/main/java/org/apache/maven/plugin/gpg/GpgSignAttachedMojo.java	(revision 832750)
+++ src/main/java/org/apache/maven/plugin/gpg/GpgSignAttachedMojo.java	(working copy)
@@ -212,6 +212,9 @@
             // ----------------------------------------------------------------------------
 
             File projectArtifact = project.getArtifact().getFile();
+            if( projectArtifact == null ) {
+            	throw new MojoExecutionException( "Cannot find file for artifact " + project.getArtifact() + "; gpg signing must occur on the same invocation as the packaging." );
+            }
 
             File projectArtifactSignature = signer.generateSignatureForArtifact( projectArtifact, pass );
Show
Geoffrey Wiseman added a comment - - edited This is the simplest patch I can imagine to improve the situation. It's not a very good solution, but it least explains the problem. A more workable solution would be to support signing previously-generated files, I would think.
### Eclipse Workspace Patch 1.0
#P maven-gpg-plugin
Index: src/main/java/org/apache/maven/plugin/gpg/GpgSignAttachedMojo.java
===================================================================
--- src/main/java/org/apache/maven/plugin/gpg/GpgSignAttachedMojo.java	(revision 832750)
+++ src/main/java/org/apache/maven/plugin/gpg/GpgSignAttachedMojo.java	(working copy)
@@ -212,6 +212,9 @@
             // ----------------------------------------------------------------------------
 
             File projectArtifact = project.getArtifact().getFile();
+            if( projectArtifact == null ) {
+            	throw new MojoExecutionException( "Cannot find file for artifact " + project.getArtifact() + "; gpg signing must occur on the same invocation as the packaging." );
+            }
 
             File projectArtifactSignature = signer.generateSignatureForArtifact( projectArtifact, pass );
Hide
Jakub Holư added a comment -

This is really confusing for a new user and can easily discourage him/her from using this plugin.

Thanks a lot Geoffrey for providing the work-around!!! /Jakub

Show
Jakub Holư added a comment - This is really confusing for a new user and can easily discourage him/her from using this plugin. Thanks a lot Geoffrey for providing the work-around!!! /Jakub
Hide
Geoffrey Wiseman added a comment -

Glad it was helpful.

Show
Geoffrey Wiseman added a comment - Glad it was helpful.
Hide
Benjamin Bentmann added a comment -

Improved error message in r908978.

Show
Benjamin Bentmann added a comment - Improved error message in r908978.

People

Vote (1)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: