尝试加载不存在的类'org.apache.maven.plugin.dependency.fromConfiguration.Artifact'的Maven依赖插件

时间:2014-05-22 15:01:38

标签: java maven

我正在为我正在尝试构建的所有项目的maven依赖插件收到一个奇怪的错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.8:copy (get-native-libs) on project tradestp-parent: Unable to parse configuration of mojo org.apache.maven.plugins:ma ven-dependency-plugin:2.8:copy: Error loading class 'org.apache.maven.plugin.dependency.fromConfiguration.Artifact' -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.8:copy (get-native-libs) on project tradestp-parent: Unable to parse c onfiguration of mojo org.apache.maven.plugins:maven-dependency-plugin:2.8:copy: Error loading class 'org.apache.maven.plugin.dependency.fromConfiguration.Artifact'
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:148)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:140)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:316)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:153)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:451)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:188)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:134)
    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.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.PluginConfigurationException: Unable to parse configuration of mojo org.apache.maven.plugins:maven-dependency-plugin:2.8:copy: Error loading class 'org.apache.maven.  plugin.dependency.fromConfiguration.Artifact'
    at org.apache.maven.plugin.internal.DefaultMavenPluginManager.populatePluginFields(DefaultMavenPluginManager.java:564)
    at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getConfiguredMojo(DefaultMavenPluginManager.java:496)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:96)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:195)
    ... 19 more
Caused by: org.codehaus.plexus.component.configurator.ComponentConfigurationException: Error loading class 'org.apache.maven.plugin.dependency.fromConfiguration.Artifact'
    at org.codehaus.plexus.component.configurator.converters.composite.CollectionConverter.fromConfiguration(CollectionConverter.java:174)
    at org.codehaus.plexus.component.configurator.converters.ComponentValueSetter.configure(ComponentValueSetter.java:218)
    at org.codehaus.plexus.component.configurator.converters.composite.ObjectWithFieldsConverter.processConfiguration(ObjectWithFieldsConverter.java:137)
    at org.codehaus.plexus.component.configurator.BasicComponentConfigurator.configureComponent(BasicComponentConfigurator.java:56)
    at org.apache.maven.plugin.internal.DefaultMavenPluginManager.populatePluginFields(DefaultMavenPluginManager.java:534)
    ... 22 more
Caused by: java.lang.ClassNotFoundException: org.apache.maven.plugin.dependency.fromConfiguration.Artifact
    at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:244)
    at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:230)
    at org.codehaus.plexus.component.configurator.converters.composite.CollectionConverter.fromConfiguration(CollectionConverter.java:161)
    ... 26 more

奇怪的是,它正在寻找的类org.apache.maven.plugin.dependency.fromConfiguration.Artifact真的不存在而且从来没有。

之前有没有人见过这个问题?为什么maven依赖插件试图加载一个不存在的类?

1 个答案:

答案 0 :(得分:1)

不确定你是否还有这个问题,但我遇到了同样的问题。

在我们的案例中,我们使用copy目标来复制依赖项。 pom如下:

<plugin>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>copy-custom-artifact</id>
            <goals>
                <goal>copy</goal>
            </goals>
            <configuration>
                <artifactItems>
                    <artifact>
                        <groupId>some.artifact.groupid</groupId>
                        <artifactId>some.artifact.artifactid</artifactId>
                    </artifact>
                </artifactItems>
            </configuration>
        </execution>
    </executions>
</plugin>

我在以下问题中找到了以下answer,其中说明了以下内容:

  

解包和复制目标必须复制一些核心解析代码。不幸的是,解析代码实际上并不是一种可用的形式。因此,这些目标不能处理版本范围,也不能直接从反应堆中解析工件(我坦率地说从未实现它们,因为它打破了太多的现有用例,是核心解决方案代码那么糟糕)

     

更好的方法是使用这些目标的xxx依赖形式。

基于此,我改变了我们的pom以使用copy-depenencies目标,如下所示:

<plugin>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>copy-custom-artifact</id>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <includeArtifactIds>some.artifact.artifactid</includeArtifactIds>
            </configuration>
        </execution>
    </executions>
</plugin>

完成此更改后,构建成功。希望这会有所帮助。