0

我正在尝试使用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为依赖项(如下所示),因为它需要该依赖项。(请参阅我前一段时间提出的问题)。

    <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());
    }
}
4

0 回答 0