Module path can't be defined
Hello! The problem is in module path. When plugin run main class, which is in module it defines the root path. Therefore, I can't use files in module because the path there isn't correct. ` Main 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>org.example</groupId>
<artifactId>RunTestId</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>ModuleOne</module>
</modules>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.6.1</version>
</dependency>
<dependency>
<groupId>org.burningwave</groupId>
<artifactId>core</artifactId>
<version>12.59.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<skip>true</skip>
<mainClass>RunTests</mainClass>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
----------------------------- module pom.xml -----------
`
<artifactId>ModuleOne</artifactId>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<skip>false</skip>
<mainClass>RunTestsModule</mainClass>
<classpathScope>test</classpathScope>
<cleanupDaemonThreads>false</cleanupDaemonThreads>
<workingDirectory>ModuleOne</workingDirectory>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>`
Actual result: The path file in module is C:/RunTests/src/main/resources/text.txt
Expected result: The path file in module is C:/RunTests/ModuleOne/src/main/resources/text.txt
Not sure if it is possible, but I would like the possibility to define a specific execution ID in a submodule and then target that from the command line:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>my-target</id>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>...</mainClass>
</configuration>
</execution>
</executions>
</plugin>
> mvn exec:java@my-target
Currently exec:java is attempted for all modules, incl. the root reactor, and generally fails for not having mainClass defined:
The parameters 'mainClass' for goal org.codehaus.mojo:exec-maven-plugin:3.1.1:java are missing or invalid
Even when I define default <skip>true</skip> for my my-target execution in the root POM (then override for the submodule execution):
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>my-target</id>
<goals>
<goal>java</goal>
</goals>
<configuration>
<skip>true</skip>
</configuration>
</execution>
</executions>
</plugin>
it fails for not having mainClass defined. I've worked it around by defining an empty default in the root POM:
<properties>
<exec.mainClass />
</properties>
This could result in a suboptimal experience with other exec:java usages – confusing error message with mainClass really not defined.
See also:
- Plugin Goal Invocation from Command Line (Maven 3.3.1+)