升级到m2eclipse 0.9.7版本后,发现一个问题,maven Assembly plugin无法工作,具体是在eclipse下执行"run as" --> "maven package"时,报错:
(我在pom.xml中重定义了package的行为,会执行maven-assembly-plugin插件)
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to create assembly: Error adding file 'net.runafter.nptt:NpttCore:jar:0.1.0' to archive:
G:\workspace\private\tools\nptt\trunk\NpttCore\target\classes isn't a file.
如果在windows命令行下直接执行mvn package,绕过eclipse和m2eclipse,就可以成功。
window -> preferences -> maven, 勾选"Debug output" 打开maven的debug开关,细看错误日志:
[DEBUG] Adding artifact: net.runafter.nptt:NpttCore:jar:0.1.0 with file:
G:\workspace\private\tools\nptt\trunk\NpttCore\target\classes to assembly location: lib/NpttCore-0.1.0.jar.
[DEBUG] Adding file: G:\workspace\private\tools\nptt\trunk\NpttCore\target\classes to archive location: NpttMain-
0.1.0/lib/NpttCore-0.1.0.jar
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to create assembly: Error adding file 'net.runafter.nptt:NpttCore:jar:0.1.0' to archive:
G:\workspace\private\tools\nptt\trunk\NpttCore\target\classes isn't a file.
[INFO] ------------------------------------------------------------------------
[DEBUG] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to create assembly: Error adding file
'net.runafter.nptt:NpttCore:jar:0.1.0' to archive: G:\workspace\private\tools\nptt\trunk\NpttCore\target\classes
isn't a file.
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:584)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle
(DefaultLifecycleExecutor.java:500)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:479)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures
(DefaultLifecycleExecutor.java:331)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments
(DefaultLifecycleExecutor.java:292)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:142)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:336)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:129)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:301)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.plugin.MojoExecutionException: Failed to create assembly: Error adding file
'net.runafter.nptt:NpttCore:jar:0.1.0' to archive: G:\workspace\private\tools\nptt\trunk\NpttCore\target\classes
isn't a file.
at org.apache.maven.plugin.assembly.mojos.AbstractAssemblyMojo.execute(AbstractAssemblyMojo.java:368)
at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:453)
at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:559)
16 more
Caused by: org.apache.maven.plugin.assembly.archive.ArchiveCreationException: Error adding file
'net.runafter.nptt:NpttCore:jar:0.1.0' to archive: G:\workspace\private\tools\nptt\trunk\NpttCore\target\classes
isn't a file.
at org.apache.maven.plugin.assembly.archive.task.AddArtifactTask.execute(AddArtifactTask.java:193)
at org.apache.maven.plugin.assembly.archive.task.AddDependencySetsTask.addDependencySet
(AddDependencySetsTask.java:177)
at org.apache.maven.plugin.assembly.archive.task.AddDependencySetsTask.execute
(AddDependencySetsTask.java:116)
at org.apache.maven.plugin.assembly.archive.phase.DependencySetAssemblyPhase.execute
(DependencySetAssemblyPhase.java:74)
at org.apache.maven.plugin.assembly.archive.DefaultAssemblyArchiver.createArchive
(DefaultAssemblyArchiver.java:129)
at org.apache.maven.plugin.assembly.mojos.AbstractAssemblyMojo.execute(AbstractAssemblyMojo.java:322)
18 more
Caused by: org.codehaus.plexus.archiver.ArchiverException:
G:\workspace\private\tools\nptt\trunk\NpttCore\target\classes isn't a file.
at org.codehaus.plexus.archiver.AbstractArchiver.addFile(AbstractArchiver.java:308)
at org.codehaus.plexus.archiver.AbstractArchiver.addFile(AbstractArchiver.java:262)
at org.apache.maven.plugin.assembly.archive.archiver.AssemblyProxyArchiver.addFile
(AssemblyProxyArchiver.java:474)
at org.apache.maven.plugin.assembly.archive.task.AddArtifactTask.execute(AddArtifactTask.java:188)
23 more
可以看到,maven Assembly plugin试图以操作文件的方式操作目录NpttCore\target\classes,因此失败造成整个package命令执行失败。
查了好一段时间,没有结果,因为之前一直都是ok的,而且在命令行下可以正常,有些糊涂。最后没有办法了,只好google,终于有所收获,同样的问题之前有人遇到过:
http://jira.codehaus.org/browse/MNGECLIPSE-1201
而且给maven的官方提过comments:
http://jira.codehaus.org/browse/MASSEMBLY-396
似乎maven的维护人员给出了答案:
This is related to workspace resolution feature that is enabled automatically if project has workspace resolution enabled. You can disable it in the Maven launch configuration.
The workspace resolution is not a new feature, you can read about it at [1]. In 0.9.7 defaults for the Maven launch configuration been changed to pickup setting for workspace dependency resolution from the project settings, so defaults for compile-time dependency resolution match Maven launch dependency resolution. Unfortunately not all Maven plugins can properly work when workspace dependency resolution is enabled, so I would recommend to submit bug reports to the Maven projects for such plugins.
The m2eclipse allows to disable workspace resolution for compile time and for Maven launch config separately, so you have some flexibility.
简单的说就是和workspace resolution这个特性有关,In 0.9.7默认的maven的启动配置已经被修改为“pickup setting for workspace dependency resolution from the project settings”,而不是所有的maven插件都可以在workspace dependency resolution开启的情况下工作。比如这次maven Assembly plugin就犯错了,可以通过在maven的启动配置中关闭这个特性来解决这个问题。
解决的方法很简单,右键单击要执行package的project,"properties for ***" -> maven,将"resolve dependencies from workspace projects"前的勾取消。
重新执行maven package成功,问题解决。