如何将 java class 从测试包添加到 Maven 插件
How to add a java class from test package to maven plugin
我想从测试包中添加一个 java class 到 exec-maven-plugin
执行。
如你所见,我试过:
<classpathScope>test</classpathScope>
并且找不到我的测试资源。
<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>
为了让执行通过,我需要来自测试 com.package
的 java class
测试资源是class执行时需要的测试注解类型接口
在解决方案中进行了更多调查后,我得出的结论是,最好在项目中创建一个新的测试模块
<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>
我在上面的模块中添加的作为测试资源:
<dependency>
<groupId>com.project</groupId>
<artifactId>project-test-module</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
我想从测试包中添加一个 java class 到 exec-maven-plugin
执行。
如你所见,我试过:
<classpathScope>test</classpathScope>
并且找不到我的测试资源。
<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>
为了让执行通过,我需要来自测试 com.package
测试资源是class执行时需要的测试注解类型接口
在解决方案中进行了更多调查后,我得出的结论是,最好在项目中创建一个新的测试模块
<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>
我在上面的模块中添加的作为测试资源:
<dependency>
<groupId>com.project</groupId>
<artifactId>project-test-module</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>