加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – Maven2编译器自定义执行源目录和目标目录

发布时间:2020-12-14 05:35:16 所属栏目:Java 来源:网络整理
导读:我想在不同的阶段运行maven编译器插件,并使用不同的sourceDirector和destinationDirector,以便可以使用除src / main / java和src / test / java之外的目录的代码. 我认为这个解决方案看起来像下面那样,我将其连接到的阶段是预集成测试.但是,testSourceDirect
我想在不同的阶段运行maven编译器插件,并使用不同的sourceDirector和destinationDirector,以便可以使用除src / main / java和src / test / java之外的目录的代码.

我认为这个解决方案看起来像下面那样,我将其连接到的阶段是预集成测试.但是,testSourceDirectory和testOutputDirectory的属性似乎没有以这种方式指定,因为它们位于POM的部分.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>

  <executions>
    <execution>
      <id>compile mytests</id>
      <goals>
        <goal>testCompile</goal>
      </goals>
      <phase>pre-integration-test</phase>
      <configuration>
        <testSourceDirectory>${basedir}/src/inttest/java</testSourceDirectory>
        <testOutputDirectory>${basedir}/target/inttest-classes</testOutputDirectory>
      </configuration>
    </execution>
  </executions>
</plugin>

有没有办法让这个插件在不同的阶段编译不同的目录,而不影响它的默认操作?

解决方法

源目录位于< build>>内的编译器插件之外.元素,所以这不行.

您可以使用build-helper-maven-plugin的add-source和add-test-source为集成测试指定其他源目录,但这不会删除现有的源目录.

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.3</version>
    <executions>
      <execution>
        <id>add-it-source</id>
        <phase>pre-integration-test</phase>
        <goals>
          <goal>add-source</goal>
        </goals>
        <configuration>
          <sources>
            <source>${basedir}/src/inttest/java</source>
          </sources>
        </configuration>
      </execution>
    </executions>
  </plugin>

如果将add-test-source目标绑定在testCompile目标之前运行,则将包括集成测试.注意你希望它们被输出到target / test-classes,所以surefire插件会找到它们.

为了处理标准测试源的删除,我写了一个小插件来修改模型以删除现有的testSource位置,然后再添加它们进行集成测试.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读