title: NoSuchElementException thrown while Testing Maven Plugin
body: <p>I am trying to test my maven plugin using the <a href="http://maven.apache.org/plugin-testing/maven-plugin-testing-harness/getting-started/index.html" rel="noreferrer"><em>maven plugin testing harness</em></a>. The only documentation I can find on the matter is rather old, and I have found <a href="https://stackoverflow.com/questions/15779351/component-lookup-exception-with-org-apache-maven-repository-repositorysystem-in"><strong>similar</strong></a> threads with the same error, but no resolution, at least not one that solves the problem for me. The error can be boiled down to a <em>NoSuchElementException</em> being thrown when trying to run the <em>lookupMojo</em> method. </p>
  
  <p>Has anyone else experience this or a similar issue, and how did you fix it? Let me know if you need any more information and I will post updates. </p>
  
  <p><strong>Plugin Class</strong></p>
  
  <pre><code>@Mojo(name = "my_plugin", defaultPhase = LifecyclePhase.CLEAN, threadSafe = true)
  public class MyPlugin extends AbstractMojo
  {
      private static final Logger logger = LoggerFactory.getLogger(MyPlugin.class);
  
      @Parameter private String configFileLocation;
  
      public void execute() throws MojoExecutionException, MojoFailureException
      {
          logger.info("The config file location is: {}", configFileLocation);
          saveSystemProperties(new File(configFileLocation));
      }
  
      private void saveSystemProperties(final File file)
      {
          logger.info("Attempting to save system properties");
          try(FileOutputStream fr = new FileOutputStream(file))
          {
              System.getProperties().store(fr, "Properties");
              logger.info("Properties successfully saved. Closing File Output Stream Implicitly");
          }
          catch(IOException e)
          {
              logger.info("There was an IO error. ");
              e.printStackTrace();
          }
      }
  } 
  </code></pre>
  
  <p><strong>Plugin Test Class</strong></p>
  
  <pre><code>public class MyPluginTester extends AbstractMojoTestCase
  {
      private static final Logger logger = LoggerFactory.getLogger(MyPluginTester.class);
  
      protected void setup() throws Exception
      {
          super.setUp();
      }
  
      protected void tearDown() throws Exception
      {
          super.tearDown();
      }
  
      public void testMojoGoal() throws Exception
      {
          logger.info("Loading Test Pom File");
          File testPom = new File(getBasedir(),"src/test/resources/pom/basic-test-plugin-config.xml");
          assertNotNull(testPom);
          MyPlugin mojo = (LittleSysStore)lookupMojo("configure", testPom);
          assertNotNull(mojo);
      }
  }
  </code></pre>
  
  <p><strong>POM File</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.my.stuff&lt;/groupId&gt;
      &lt;artifactId&gt;my-maven-plugin&lt;/artifactId&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;maven-plugin&lt;/packaging&gt;
  
      &lt;properties&gt;
          &lt;maven.plugin.annotations.version&gt;3.5&lt;/maven.plugin.annotations.version&gt;
          &lt;maven.plugin.testing.version&gt;3.3.0&lt;/maven.plugin.testing.version&gt;
          &lt;maven.version&gt;3.5.0&lt;/maven.version&gt;
          &lt;slf4j.version&gt;1.7.25&lt;/slf4j.version&gt;
          &lt;junit.version&gt;4.12&lt;/junit.version&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
      &lt;/properties&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;${java.version}&lt;/source&gt;
                      &lt;target&gt;${java.version}&lt;/target&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.maven&lt;/groupId&gt;
              &lt;artifactId&gt;maven-artifact&lt;/artifactId&gt;
              &lt;version&gt;${maven.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.maven&lt;/groupId&gt;
              &lt;artifactId&gt;maven-compat&lt;/artifactId&gt;
              &lt;version&gt;${maven.version}&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.maven&lt;/groupId&gt;
              &lt;artifactId&gt;maven-core&lt;/artifactId&gt;
              &lt;version&gt;${maven.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.maven&lt;/groupId&gt;
              &lt;artifactId&gt;maven-model&lt;/artifactId&gt;
              &lt;version&gt;${maven.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.maven&lt;/groupId&gt;
              &lt;artifactId&gt;maven-plugin-api&lt;/artifactId&gt;
              &lt;version&gt;${maven.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.maven.plugin-tools&lt;/groupId&gt;
              &lt;artifactId&gt;maven-plugin-annotations&lt;/artifactId&gt;
              &lt;version&gt;${maven.plugin.annotations.version}&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.maven.plugin-testing&lt;/groupId&gt;
              &lt;artifactId&gt;maven-plugin-testing-harness&lt;/artifactId&gt;
              &lt;version&gt;${maven.plugin.testing.version}&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
              &lt;artifactId&gt;slf4j-simple&lt;/artifactId&gt;
              &lt;version&gt;${slf4j.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;junit&lt;/groupId&gt;
              &lt;artifactId&gt;junit&lt;/artifactId&gt;
              &lt;version&gt;${junit.version}&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <pre><code>org.codehaus.plexus.component.repository.exception.ComponentLookupException: java.util.NoSuchElementException
        role: org.apache.maven.plugin.Mojo
    roleHint: com.my.stuff-maven-plugin:1.0-SNAPSHOT:clean
      at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:267)
      at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:243)
      at org.codehaus.plexus.PlexusTestCase.lookup(PlexusTestCase.java:205)
      at org.apache.maven.plugin.testing.AbstractMojoTestCase.lookupMojo(AbstractMojoTestCase.java:410)
      at org.apache.maven.plugin.testing.AbstractMojoTestCase.lookupMojo(AbstractMojoTestCase.java:355)
      at unit_tests.LittleSysStoreTest.testMojoGoal(LittleSysStoreTest.java:33)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at junit.framework.TestCase.runTest(TestCase.java:176)
      at junit.framework.TestCase.runBare(TestCase.java:141)
      at junit.framework.TestResult$1.protect(TestResult.java:122)
      at junit.framework.TestResult.runProtected(TestResult.java:142)
      at junit.framework.TestResult.run(TestResult.java:125)
      at junit.framework.TestCase.run(TestCase.java:129)
      at junit.framework.TestSuite.runTest(TestSuite.java:252)
      at junit.framework.TestSuite.run(TestSuite.java:247)
      at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
      at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
      at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
      at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
      at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
      at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
      Caused by: java.util.NoSuchElementException
      at java.util.Collections$EmptyIterator.next(Collections.java:4189)
      at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:263)
      ... 23 more
  </code></pre>