java - 是否可以通过命令行将可选参数 testInincludes 或 testExcludes 传递给 maven 编译插件?

标签 java maven maven-3 maven-compiler-plugin

  1. 是否可以通过命令行将可选参数 testInincludes 或 testExcludes 传递给 maven 编译插件?
    我需要传递一些 .java 作为可选参数。


类似于

mvn clean verify test-compile -DtestIncludes=**/course/MyTest.java,**/course/CompileMeWithMyTest.java,etc

在页面上http://maven.apache.org/plugins/maven-compiler-plugin/testCompile-mojo.html testInincludes 和 testExcludes 没有提到用户属性


测试包括:
编译器的包含过滤器列表。
类型:java.util.Set
自:2.0
必填:否

测试排除:
编译器的排除过滤器列表。
类型:java.util.Set
自:2.0
必填:否

  • 如果问题 1 没有任何可能的变体。 是否可以使用命令行在下一个配置文件中设置包含/排除 java 类/文件夹。

     <profile>
        <id>only-necessary-classes</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.3</version>
                    <configuration>
                        <source>${java-version}</source>
                        <target>${java-version}</target>
                    </configuration>
                    <executions>
                        <execution>
                            <id>default-testCompile</id>
                            <phase>test-compile</phase>
                            <configuration>
                                <testIncludes>
                                    <include>**/tests/projectname/course/CheckQuizWithNewAccount.java</include>
                                    <include>**/tests/projectname/course/V8GenericTests.java</include>
                                </testIncludes>
                            </configuration>
                            <goals>
                                <goal>testCompile</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </profile>
    
  • 最佳答案

    创建您自己的属性并在 testIncludes\testExcludes block 中使用它。

    mvn clean verify -Dinclude=**/course/MyTest.java

    <properties>
        <include>some test</include>
    </properties>
    
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <source>${java-version}</source>
                    <target>${java-version}</target>
                </configuration>
                <executions>
                    <execution>
                        <id>default-testCompile</id>
                        <phase>test-compile</phase>
                        <configuration>
                            <testIncludes>
                                <include>${include}</include>
                            </testIncludes>
                        </configuration>
                        <goals>
                            <goal>testCompile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    

    关于java - 是否可以通过命令行将可选参数 testInincludes 或 testExcludes 传递给 maven 编译插件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31207529/

    相关文章:

    java - 在 Scanner 类中采用可变参数

    java - 在 Spring MVC Hibernate 应用程序中,我应该在哪里保存用户图像?

    java - 将动态对象放入数据结构中

    maven - spring boot war中缺少json-simple.jar

    java - 为什么值没有正确增加?

    java - 运行exec-maven-plugin java时如何获取 "[DEBUG] Executing command line:"

    maven - 什么是Maven存储库镜像的gradle等效项?

    java - 在 junit 窗口中运行 maven 测试

    tomcat - 使用 Maven 进行在线开发的标准方法

    maven - 使用 Maven exec 插件启动 Windows 批处理脚本会阻止构建,即使该脚本使用 "start"