I am trying to use Mojo-Executor and trying out the example of copy-dependencies
on that link. According to the instructions, I have included it as dependency in my maven plugin POM and have created a mojo as following:
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;
}
Because it has BuildPluginManager
, I have to include maven-core
as dependency (as below) since it needs that dependency. (See the question I asked some time ago for that).
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.2.5</version>
</dependency>
Problem is after adding that particular dependency in the POM file of the maven-plugin, My tests stop working and give following error:
-------------------------------------------------------
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)
I am explicitly seeing this error only after adding the dependency. If I comment out the dependency maven-core
, I get the error saying it does not recognize the symbol BuildPluginManager
(which is why I need the dependency in the first place).
I have also tried a few different versions of maven-core
, but same error. How do I make the error go away while keeping the dependency?
EDIT 1:
The test code: (please note that it works as intended when the maven-core
dependency is not introduced.
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());
}
}