title: maven - advice on usage of multi-modules (jar, war, …) project
body: <p>I have the following Maven organization:</p>
  
  <pre><code>- ./pom.xml (top-level project, which defines the 4 modules below)
     - ./a/pom.xml (library jar)
     - ./b/pom.xml (library jar)
     - ./c/pom.xml (war)
     - ./d/pom.xml (executable jar)
  </code></pre>
  
  <p>For building and deploying the <code>c</code> project, I do:</p>
  
  <pre><code>mvn verify tomcat7:redeploy -pl c -am
  </code></pre>
  
  <p>For building and executing the <code>d</code> project, I do:</p>
  
  <pre><code>mvn verify exec:java -pl d -am
  </code></pre>
  
  <p>For <code>d</code> there is a problem. Maven reports:</p>
  
  <pre><code>[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.4.0:java (default-cli)
  on project parent: The parameters 'mainClass' for goal
  org.codehaus.mojo:exec-maven-plugin:1.4.0:java are missing or invalid -&gt; [Help 1]
  </code></pre>
  
  <p>This is indeed correct, the parent <code>pom.xml</code> has no configuration for <code>exec</code>. Only the <code>d</code> project has a configuration for <code>exec</code>.</p>
  
  <p>This question is a little variation of question <a href="https://stackoverflow.com/questions/33196340/maven-advice-on-usage-of-multi-modules-jar-war-project">maven - advice on usage of multi-modules (jar, war, ...) project</a>, so I decided to dedicate a separate question for it.</p>
  
  <p>Why does Maven try to <code>exec</code> on the parent project?</p>
  
  <p><strong>update</strong></p>
  
  <p>I abstracted the same problem in following three pom files:</p>
  
  <p>The parent pom:</p>
  
  <pre><code>&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/maven-v4_0_0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;test&lt;/groupId&gt;
      &lt;artifactId&gt;parent&lt;/artifactId&gt;
      &lt;packaging&gt;pom&lt;/packaging&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;parent&lt;/name&gt;
  
      &lt;modules&gt;
          &lt;module&gt;a&lt;/module&gt;
          &lt;module&gt;b&lt;/module&gt;
      &lt;/modules&gt;
  
      &lt;build&gt;
          &lt;pluginManagement&gt;
              &lt;plugins&gt;
                  &lt;plugin&gt;
                      &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
                      &lt;artifactId&gt;exec-maven-plugin&lt;/artifactId&gt;
                      &lt;version&gt;1.4.0&lt;/version&gt;
                  &lt;/plugin&gt;
              &lt;/plugins&gt;
          &lt;/pluginManagement&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>The a pom:</p>
  
  <pre><code>&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/maven-v4_0_0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;parent&gt;
          &lt;groupId&gt;test&lt;/groupId&gt;
          &lt;artifactId&gt;parent&lt;/artifactId&gt;
          &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
      &lt;/parent&gt;
  
      &lt;artifactId&gt;a&lt;/artifactId&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;a&lt;/name&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>The b pom:</p>
  
  <pre><code>&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/maven-v4_0_0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;parent&gt;
          &lt;groupId&gt;test&lt;/groupId&gt;
          &lt;artifactId&gt;parent&lt;/artifactId&gt;
          &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
      &lt;/parent&gt;
  
      &lt;artifactId&gt;b&lt;/artifactId&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;b&lt;/name&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;test&lt;/groupId&gt;
              &lt;artifactId&gt;a&lt;/artifactId&gt;
              &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt;
                  &lt;artifactId&gt;exec-maven-plugin&lt;/artifactId&gt;
                  &lt;configuration&gt;
                      &lt;mainClass&gt;MyMainClass&lt;/mainClass&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>The command I am executing is:</p>
  
  <pre><code>mvn verify exec:java -pl b -am
  </code></pre>
  
  <p>This can also be found at <a href="https://github.com/jeperjaperjieper/issue-33197130" rel="nofollow noreferrer">https://github.com/jeperjaperjieper/issue-33197130</a>.</p>