Search code examples
javamavenexec-maven-plugin

How to add a java class from test package to maven plugin


I want to add a java class from test package to exec-maven-plugin execution.

As you can see bellow I tried with:

<classpathScope>test</classpathScope>

And my test resource is not found.

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>generateIgniteSchemaClasses</id>
                    <phase>process-test-resources</phase>
                    <goals>
                        <goal>java</goal>
                    </goals>
                    <configuration>
                        <executableDependency>
                            <groupId>com.package</groupId>
                            <artifactId>ignite-schema-import</artifactId>
                        </executableDependency>
                        <mainClass>com.package.SchemaImportApplication</mainClass>
                        <arguments>
                            <argument>${project.build.testOutputDirectory}/xml/schema.xml</argument>
                        </arguments>
                        <classpathScope>test</classpathScope>
                    </configuration>
                </execution>
            </executions>
        </plugin>

and In order for the execution to pass I need a java class from test com.package

The test resource is a test annotation type interface which is required in the class's execution.


Solution

  • After investigating some more in a solution, I got to the conclusion that it is better to create a new test module in the project

    <build>
        <plugins>
            <!-- This is a test module, so it does not need to be deployed -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <configuration>
                    <skip>true</skip>
                </configuration>
            </plugin>
        </plugins>
    </build>
    

    which I added in the above module as a test resource:

        <dependency>
            <groupId>com.project</groupId>
            <artifactId>project-test-module</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>