0

My problem is the following: executing some code when building a Maven project. I browsed this forum and found this guide. For such purpose, I created a parent project and this is its pom.xml:

<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">
  <modelVersion>4.0.0</modelVersion>
  <groupId>it.dependency</groupId>
  <artifactId>parent-node</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
  <modules>
    <module>compilation-node</module>
    <module>building-module</module>
  </modules>
</project>

Then, I created a child project, whose role is simply containing a class with a main, in which I plan to insert my custom code. The package hosting the class is placed inside src/main/java. This is the test content of aformentioned class:

package compilation.node;

public class Compilation {
    public static void main(String[]args)
    {
        System.out.println("Compilation printing");
    }
}

This is the pom.xml of this child project:

<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">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>it.dependency</groupId>
    <artifactId>parent-node</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <artifactId>compilation-node</artifactId>
</project>

Finally, I created another child project, which is the one I need to build and that has to execute custom code at building time. This is its pom.xml:

<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">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>it.dependency</groupId>
    <artifactId>parent-node</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <artifactId>building-module</artifactId>

  <dependencies>
    <dependency>
      <groupId>it.dependency</groupId>
    <artifactId>compilation-node</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <scope>compile</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.6.0</version>
        <executions>
          <execution>
            <goals>
              <goal>java</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <mainClass>compilation.node.Compilation</mainClass>
        </configuration>
      </plugin>
    </plugins>
  </build>

</project>

I verified that second child project is effectively dependent on its sibling using a test class, anyway when I build second child (from Eclipse, with a right click on it and choosing Run as -> Maven install), the code I need and that is placed in the other child project is not executed. Can you tell me why?

Thanks in advance for your support.

Bia
  • 165
  • 1
  • 3
  • 12

0 Answers0