栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

适用于测试和主要版本的不同Maven编译器版本

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

适用于测试和主要版本的不同Maven编译器版本

如果要设置对相关Java版本的遵从性,则可以为每次执行配置编译器插件。假设Maven使用的JDK至少与您指定的最高版本相同。通过使用属性,可以在命令行或子项中覆盖该配置(如果需要):

<plugin>  <groupId>org.apache.maven.plugins</groupId>  <artifactId>maven-compiler-plugin</artifactId>  <configuration>    <source>${compileSource}</source>    <target>${compileSource}</target>  </configuration>  <executions>    <execution>      <id>test-compile</id>      <phase>process-test-sources</phase>      <goals>        <goal>testCompile</goal>      </goals>      <configuration>        <source>${testCompileSource}</source>        <target>${testCompileSource}</target>      </configuration>    </execution>  </executions></plugin>...<properties>  <compileSource>1.4</compileSource>  <testCompileSource>1.5</testCompileSource></properties>

如果您打算使用其他 编译器
,则涉及的更多。因为您需要指定JDK的路径以及所使用的编译器版本。同样,这些可以在属性中定义。尽管您可能想在settings.xml中定义它们

<plugin>  <groupId>org.apache.maven.plugins</groupId>  <artifactId>maven-compiler-plugin</artifactId>  <configuration>    <source>${compileSource}</source>    <target>${compileSource}</target>    <executable>${compileJdkPath}/bin/javac</executable>    <compilerVersion>${compileSource}</compilerVersion>  </configuration>  <executions>    <execution>      <id>test-compile</id>      <phase>process-test-sources</phase>      <goals>        <goal>testCompile</goal>      </goals>      <configuration>        <source>${testCompileSource}</source>        <target>${testCompileSource}</target>        <executable>${testCompileJdkPath}/bin/javac</executable>        <compilerVersion>${testCompileSource}</compilerVersion>      </configuration>    </execution>  </executions></plugin>...<properties>  <compileSource>1.4</compileSource>  <testCompileSource>1.5</testCompileSource>  <compileJdkPath>path/to/jdk</compileJdkPath>  <testCompileJdkPath>path/to/test/jdk<testCompileJdkPath></properties>

注意,在配置文件中定义编译器配置可能是有意义的,对于您支持的每个JDK,一个配置文件都可以使用,以便您的常规构建不依赖于所设置的属性。

另外, 在Maven 3.x中,

fork
在指定可执行文件时需要包括参数,例如:

  <plugin>    <artifactId>maven-compiler-plugin</artifactId>    <version>3.1</version>    <executions>      <execution>        <id>default-testCompile</id>        <phase>test-compile</phase>        <goals>          <goal>testCompile</goal>        </goals>        <configuration>          <fork>true</fork>          <executable>${testCompileJdkPath}/bin/javac</executable>          <source>1.8</source>          <target>1.8</target>        </configuration>       </execution>    </executions>  </plugin>


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/495018.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号