Maven war 插件失败并出现错误 "No such field org.apache.maven.model.Dependency.managementKey"

Maven war plugin is failing with error "No such field org.apache.maven.model.Dependency.managementKey"

我们将 Maven 3.2.3 与 Jenkins (Java 6) 一起使用。我们正在构建一个多模块项目。然而,一些项目在 运行 maven-war-plugin 目标上失败了。这是配置…

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        <useCache>true</useCache>
        <cacheFile>/tmp/${project.artifactId}/war/work</cacheFile>
    </configuration>
</plugin>

下面是错误信息。我们使用的命令是“mvn clean install”

[INFO] Total time: 02:59 min
[INFO] Finished at: 2015-09-03T18:08:08+00:00
[INFO] Final Memory: 53M/695M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.6:war (default-war) on project orgsclient: Execution default-war of goal org.apache.maven.plugins:maven-war-plugin:2.6:war failed: No such field org.apache.maven.model.Dependency.managementKey
[ERROR] ---- Debugging information ----
[ERROR] field               : managementKey
[ERROR] class               : org.apache.maven.model.Dependency
[ERROR] required-type       : org.apache.maven.model.Dependency
[ERROR] converter-type      : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
[ERROR] path                : /webapp-structure/dependenciesInfo/org.apache.maven.plugin.war.util.DependencyInfo/dependency/managementKey
[ERROR] class[1]            : org.apache.maven.plugin.war.util.DependencyInfo
[ERROR] class[2]            : java.util.ArrayList
[ERROR] converter-type[1]   : com.thoughtworks.xstream.converters.collections.CollectionConverter
[ERROR] class[3]            : org.apache.maven.plugin.war.util.WebappStructure
[ERROR] version             : null
[ERROR] -------------------------------
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.6:war (default-war) on project orgsclient: Execution default-war of goal org.apache.maven.plugins:maven-war-plugin:2.6:war failed: No such field org.apache.maven.model.Dependency.managementKey
---- Debugging information ----
field               : managementKey
class               : org.apache.maven.model.Dependency
required-type       : org.apache.maven.model.Dependency
converter-type      : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path                : /webapp-structure/dependenciesInfo/org.apache.maven.plugin.war.util.DependencyInfo/dependency/managementKey
class[1]            : org.apache.maven.plugin.war.util.DependencyInfo
class[2]            : java.util.ArrayList
converter-type[1]   : com.thoughtworks.xstream.converters.collections.CollectionConverter
class[3]            : org.apache.maven.plugin.war.util.WebappStructure
version             : null
-------------------------------
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:224)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:347)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:154)
    at org.jvnet.hudson.maven3.launcher.Maven32Launcher.main(Maven32Launcher.java:132)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchStandard(Launcher.java:330)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:238)
    at jenkins.maven3.agent.Maven32Main.launch(Maven32Main.java:181)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at hudson.maven.Maven3Builder.call(Maven3Builder.java:136)
    at hudson.maven.Maven3Builder.call(Maven3Builder.java:71)
    at hudson.remoting.UserRequest.perform(UserRequest.java:121)
    at hudson.remoting.UserRequest.perform(UserRequest.java:49)
    at hudson.remoting.Request.run(Request.java:325)
    at hudson.remoting.InterceptingExecutorService.call(InterceptingExecutorService.java:68)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-war of goal org.apache.maven.plugins:maven-war-plugin:2.6:war failed: No such field org.apache.maven.model.Dependency.managementKey
---- Debugging information ----
field               : managementKey
class               : org.apache.maven.model.Dependency
required-type       : org.apache.maven.model.Dependency
converter-type      : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path                : /webapp-structure/dependenciesInfo/org.apache.maven.plugin.war.util.DependencyInfo/dependency/managementKey   
class[1]            : org.apache.maven.plugin.war.util.DependencyInfo
class[2]            : java.util.ArrayList
converter-type[1]   : com.thoughtworks.xstream.converters.collections.CollectionConverter
class[3]            : org.apache.maven.plugin.war.util.WebappStructure
version             : null
-------------------------------
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:143)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    ... 30 more
Caused by: com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$UnknownFieldException: No such field org.apache.maven.model.Dependency.managementKey
---- Debugging information ----
field               : managementKey
class               : org.apache.maven.model.Dependency
required-type       : org.apache.maven.model.Dependency
converter-type      : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
path                : /webapp-structure/dependenciesInfo/org.apache.maven.plugin.war.util.DependencyInfo/dependency/managementKey
class[1]            : org.apache.maven.plugin.war.util.DependencyInfo
class[2]            : java.util.ArrayList
converter-type[1]   : com.thoughtworks.xstream.converters.collections.CollectionConverter
class[3]            : org.apache.maven.plugin.war.util.WebappStructure
version             : null
-------------------------------
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.determineType(AbstractReflectionConverter.java:453)
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:294)
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:234)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
    at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshallField(AbstractReflectionConverter.java:355)
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:306)
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:234)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
    at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50)
    at com.thoughtworks.xstream.converters.collections.AbstractCollectionConverter.readItem(AbstractCollectionConverter.java:71)
    at com.thoughtworks.xstream.converters.collections.CollectionConverter.addCurrentElementToCollection(CollectionConverter.java:79)
    at com.thoughtworks.xstream.converters.collections.CollectionConverter.populateCollection(CollectionConverter.java:72)
    at com.thoughtworks.xstream.converters.collections.CollectionConverter.populateCollection(CollectionConverter.java:66)
    at com.thoughtworks.xstream.converters.collections.CollectionConverter.unmarshal(CollectionConverter.java:61)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
    at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshallField(AbstractReflectionConverter.java:355)
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.doUnmarshal(AbstractReflectionConverter.java:306)
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:234)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:72)
    at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:65)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:66)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:50)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:134)
    at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:32)
    at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1058)
    at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:1042)
    at com.thoughtworks.xstream.XStream.fromXML(XStream.java:913)
    at org.apache.maven.plugin.war.util.WebappStructureSerializer.fromXml(WebappStructureSerializer.java:78)
    at org.apache.maven.plugin.war.AbstractWarMojo.buildWebapp(AbstractWarMojo.java:448)
    at org.apache.maven.plugin.war.AbstractWarMojo.buildExplodedWebapp(AbstractWarMojo.java:420)
    at org.apache.maven.plugin.war.WarMojo.performPackaging(WarMojo.java:212)
    at org.apache.maven.plugin.war.WarMojo.execute(WarMojo.java:175)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
    ... 31 more

这个错误是什么意思?我完全不知所措。

不要使用 <useCache>

根据Apache Maven WAR Plugin [v2.6] > war:war,它是一个

Experimental feature so disabled by default.

有同样的问题,甚至没有指定 useCache。通过将 <useCache>false</useCache> 直接添加到 <configuration>.

来解决它