Skip to content

mvn clean install时报错NullPointerException

  • 报错信息

    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor (default-descriptor) on project docker-image-builder: Execution default-descriptor of goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor failed.: NullPointerException -> [Help 1]
    [ERROR] 
    [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
    [ERROR] Re-run Maven using the -X switch to enable full debug logging.
    [ERROR] 
    [ERROR] For more information about the errors and possible solutions, please read the following articles:
    [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
    
    Process finished with exit code 1

    image-20250722171303670

  • 解决方案:maven-plugin-plugin从3.2更新到3.5.1

    image-20250722171416912

  • 参考文档

如何在maven插件项目中处理项目源

  • 解释:我想在maven插件中获取到使用该插件的项目的一些信息(如项目名称等)

  • 步骤

    • 在maven插件项目中导入依赖

      xml
      <dependency>
          <groupId>org.apache.maven</groupId>
          <artifactId>maven-project</artifactId>
          <version>2.0.6</version>
      </dependency>
    • 在Mojo中使用

      java
      @Mojo( name = "xxx", defaultPhase = LifecyclePhase.PROCESS_SOURCES )
      public class TestMojo extends AbstractMojo {
          @Parameter(defaultValue = "${project}", required = true, readonly = true)
      	private MavenProject project;
          
          @Override
          public void execute() {
              String projectName = project.getName();
          }
      }
    • MavenPorject详情解释请跳转查看 MavenProject (Apache Maven 3.8.5 API)

  • 参考文档

MIT版权,未经许可禁止任何形式的转载