首页 > 解决方案 > org.eclipse.m2e.core 插件在 Eclipse 中命中 NullPointerException

问题描述

在 Eclipse Oxygen 中导入了一个 Maven 项目,并在构建项目时使用org.eclipse.m2e.core插件解决了这个问题。m2e版本是1.8.3,有人知道为什么会这样吗?我从很久以前就在错误报告中看到过类似的问题,但从 1.1 版开始,它们被标记为已修复。

java.lang.NullPointerException
at org.eclipse.m2e.core.internal.lifecyclemapping.model.PluginExecutionMetadata.getAction(PluginExecutionMetadata.java:144)
at org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory.isConfigurator(LifecycleMappingFactory.java:718)
at org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory.calculateEffectiveLifecycleMappingMetadata0(LifecycleMappingFactory.java:602)
at org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory.calculateEffectiveLifecycleMappingMetadata(LifecycleMappingFactory.java:535)
at org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory.calculateEffectiveLifecycleMappingMetadata(LifecycleMappingFactory.java:249)
at org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory.calculateLifecycleMapping(LifecycleMappingFactory.java:181)
at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.setupLifecycleMapping(ProjectRegistryManager.java:594)
at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.refreshPhase2(ProjectRegistryManager.java:513)
at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager$3.call(ProjectRegistryManager.java:492)
at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager$3.call(ProjectRegistryManager.java:1)
at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:177)
at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:151)
at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.refresh(ProjectRegistryManager.java:496)
at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.refresh(ProjectRegistryManager.java:351)
at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.refresh(ProjectRegistryManager.java:298)
at org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod.getProjectFacade(MavenBuilder.java:154)
at org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod$1.call(MavenBuilder.java:89)
at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:177)
at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:151)
at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:99)
at org.eclipse.m2e.core.internal.builder.MavenBuilder$BuildMethod.execute(MavenBuilder.java:86)

此外,如果您真的去尝试在这里查看代码:

https://github.com/eclipse/m2e-core/tree/m2e-1.8.x/org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping

这个包似乎不存在?WTH在这里发生吗?这个项目是不是被分叉了,我找错地方了?我是否应该打包并开始使用 IntelliJ,似乎 m2e 在 Eclipse 中变得难以管理。生命周期映射在父级中定义为

  <pluginManagement>
    <plugin>
      <groupId>org.eclipse.m2e</groupId>
      <artifactId>lifecycle-mapping</artifactId>
      <version>1.0.0</version>
      <configuration>
        <lifecycleMappingMetadata>
          <pluginExecutions>
            <pluginExecution>
              <pluginExecutionFilter>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <versionRange>[2.10,)</versionRange>
                <goals>
                  <goal>unpack-dependencies</goal>
                </goals>
              </pluginExecutionFilter>
            </pluginExecution>
          </pluginExecutions>
        </lifecycleMappingMetadata>
      </configuration>
    </plugin>
  </pluginManagement>

标签: eclipseeclipse-pluginm2e

解决方案


PluginExecutionMetadata 是使用modello生命周期映射元数据模型.xml 生成的

生成的代码中发生 NPE 的行是

org.codehaus.plexus.util.xml.Xpp3Dom actionDom = ((org.codehaus.plexus.util.xml.Xpp3Dom) getActionDom()).getChild(0);

这指向了答案:在您的 xml 片段中,<action>缺少所需的标记,例如:

             </pluginExecutionFilter>
             <action>
               <ignore/>
             </action>
           </pluginExecution>

推荐阅读