【问题标题】:Maven, how to run test-compile together with compileMaven,如何与 compile 一起运行 test-compile
【发布时间】:2020-05-17 07:57:04
【问题描述】:

我有一个使用注释处理器的代码,当我编译类时,可以从src/main/java 类开始,但是没有编译测试(src/test/java)类,这样我自然不能运行我的单元测试,为此,我必须手动运行mvn test-compile 命令。

如何配置 pom.xml 文件以使用 maven-compiler-plugincompile 命令运行 test-compile

这是我的构建:


    <build>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.7.0</version>
          <configuration>
            <source>1.8</source>
            <target>1.8</target>
            <compilerArgs>
              <arg>-parameters</arg>
            </compilerArgs>
            <annotationProcessorPaths>
              <path>
                <groupId>io.micronaut</groupId>
                <artifactId>micronaut-inject-java</artifactId>
                <version>${micronaut.version}</version>
              </path>
              <path>
                <groupId>io.micronaut</groupId>
                <artifactId>micronaut-validation</artifactId>
                <version>${micronaut.version}</version>
              </path>
            </annotationProcessorPaths>
          </configuration>
          <executions>
            <execution>
              <id>test-compile</id>
              <goals>
                <goal>testCompile</goal>
              </goals>
              <configuration>
                <compilerArgs>
                  <arg>-parameters</arg>
                </compilerArgs>
                <annotationProcessorPaths>
                  <path>
                    <groupId>io.micronaut</groupId>
                    <artifactId>micronaut-inject-java</artifactId>
                    <version>${micronaut.version}</version>
                  </path>
                  <path>
                    <groupId>io.micronaut</groupId>
                    <artifactId>micronaut-validation</artifactId>
                    <version>${micronaut.version}</version>
                  </path>
                </annotationProcessorPaths>
              </configuration>
            </execution>
          </executions>
        </plugin>
      </plugins>
  </build>

使用apache-maven-3.6.2 + Eclipse 2019-09

【问题讨论】:

  • 下面我的回答能回答你的问题吗?
  • 很遗憾,没有,注释处理器在 Eclipse IDE 中无法正常运行,我正在尝试使用 maven-compiler-plugin+Eclipse 解决问题,而不是单独使用 maven ,命令行完美运行。

标签: java maven maven-compiler-plugin


【解决方案1】:

我并不完全清楚你想要什么。

Maven 有一个生命周期。如果你调用一个特定的阶段(如test-compile),所有之前的阶段也会被自动调用。

所以如果你想编译你的类和测试类,你只需调用mvn test-compile。如果您想编译您的类和测试类并运行测试,请致电mvn test

【讨论】:

  • 如果我运行mvn test-compile,注释处理器会生成将被注入的类。但是使用 eclipse 中的Build all 会生成单元测试类,而 Annotation Processor 不会生成这些类。我认为这是注释处理器的 Eclipse 错误,所以我试图通过 pom.xml 用另一种方法来解决,以强制 eclipse 正确运行注释处理器。
  • 什么是“全部构建”?这听起来不像是 Maven 命令。要构建整个项目,请致电clean verifyclean install。通过“运行方式”->“Maven 构建...”来执行此操作。
  • 谢谢,这很有效,在 Eclipse 中配置了一个 maven 命令。我在 Eclipse 中寻找Ctrl+B。但是Run As 没关系。再次感谢。
【解决方案2】:

我只想运行命令:mvn clean install

【讨论】:

  • 我正在寻找一种与Eclipse + maven-compiler-plugin 一起运行的方法,只需 maven 即可。
  • 要从 Eclipse 构建 Maven 项目,请使用“Run As” -> “Maven build...”,然后输入例如clean install。您没有显式调用任何其他 Eclipse 机制。
猜你喜欢
  • 2012-09-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-15
  • 2020-06-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多