Maven:添加maven-core依赖性导致PlexusContainerException

时间:2017-02-01 01:27:54

标签: java maven maven-dependency

我正在尝试使用Mojo-Executor并在该链接上尝试copy-dependencies的示例。根据说明,我将它作为依赖包含在我的maven插件POM中,并创建了一个mojo,如下所示:

package executors;

import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.project.MavenProject;
import org.apache.maven.plugin.BuildPluginManager;
import static org.twdata.maven.mojoexecutor.MojoExecutor.*;

public class SomeNameMojo extends AbstractMojo{

    @Component
    private MavenProject mavenProject;

    @Component
    private MavenSession mavenSession;

    @Component
    private BuildPluginManager pluginManager;

}

因为它有BuildPluginManager,所以我必须包含maven-core作为依赖项(如下所示),因为它需要依赖项。 (请参阅question I asked some time ago)。

    <dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-core</artifactId>
        <version>3.2.5</version>
    </dependency>

问题是在maven-plugin的POM文件中添加该特定依赖项后,我的测试停止工作并发出以下错误:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.name.name2.maven.plugin.somemavenplugin.SomeMojoTest
Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.343 sec <<< FAILURE!
testDeleteFilesTrue(com.name.name2.maven.plugin.somemavenplugin.SomeMojoTest)  Time elapsed: 0.269 sec  <<< ERROR!
org.codehaus.plexus.PlexusContainerException: Error starting container
    at org.codehaus.plexus.DefaultPlexusContainer.start(DefaultPlexusContainer.java:795)
    at org.codehaus.plexus.PlexusTestCase.setUp(PlexusTestCase.java:121)

我只是在添加依赖项后才明确看到此错误。如果我注释掉依赖项maven-core,我会收到错误,说它无法识别符号BuildPluginManager(这就是我首先需要依赖项的原因)。

我还尝试过几个不同版本的maven-core,但错误相同。如何在保持依赖性的同时消除错误?

编辑1: 测试代码:(请注意,当未引入maven-core依赖项时,它可以正常工作。

public class DeleteFilesInBundleDirMojoTest extends AbstractMojoTestCase {

    String userDir = System.getProperty("user.dir");
    File fileToBeDeleted = new File(userDir + "/test_1_file.txt");
    File fileNotToBeDeleted = new File(userDir + "/test_3_file.txt");

    /** {@inheritDoc} */
    @Override
    public void setUp() throws Exception {
        // required
        super.setUp();
    }

    /** {@inheritDoc} */
    @Override
    protected void tearDown() throws Exception {
        // required
        super.tearDown();
    }

    /**
     * @throws Exception
     *             if any
     */
    public void testDeleteFilesTrue() throws Exception {
        Boolean temp = fileToBeDeleted.createNewFile();
        assertNotNull(temp);
        assertTrue(fileToBeDeleted.exists());

        File fileDir = new File(userDir);
        String[] wildcardFilters1 = { "test_1*.txt", "test_2*.txt" };
        List<String> deletedFiles1 = PackagingUtils.deleteFiles(fileDir, wildcardFilters1);
        assertFalse(deletedFiles1.isEmpty());
        assertFalse(fileToBeDeleted.exists());
    }

    public void testDeleteFilesFalse() throws Exception {
        Boolean temp = fileNotToBeDeleted.createNewFile();
        assertNotNull(temp);
        assertTrue(fileNotToBeDeleted.exists());

        File fileDir = new File(userDir);
        String[] wildcardFilters2 = { "test_1*.txt", "test_2*.txt" };
        List<String> deletedFiles2 = PackagingUtils.deleteFiles(fileDir, wildcardFilters2);
        assertTrue(deletedFiles2.isEmpty());
        assertTrue(fileNotToBeDeleted.exists());
        assertTrue(fileNotToBeDeleted.delete());
    }
}

0 个答案:

没有答案