• <i id='rZt5U'><tr id='rZt5U'><dt id='rZt5U'><q id='rZt5U'><span id='rZt5U'><b id='rZt5U'><form id='rZt5U'><ins id='rZt5U'></ins><ul id='rZt5U'></ul><sub id='rZt5U'></sub></form><legend id='rZt5U'></legend><bdo id='rZt5U'><pre id='rZt5U'><center id='rZt5U'></center></pre></bdo></b><th id='rZt5U'></th></span></q></dt></tr></i><div id='rZt5U'><tfoot id='rZt5U'></tfoot><dl id='rZt5U'><fieldset id='rZt5U'></fieldset></dl></div>

    <small id='rZt5U'></small><noframes id='rZt5U'>

      • <bdo id='rZt5U'></bdo><ul id='rZt5U'></ul>

      <legend id='rZt5U'><style id='rZt5U'><dir id='rZt5U'><q id='rZt5U'></q></dir></style></legend>

        <tfoot id='rZt5U'></tfoot>

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

        Different maven compiler versions for test and main(用于测试和主要的不同 Maven 编译器版本)
          <tfoot id='V05U7'></tfoot>
        • <i id='V05U7'><tr id='V05U7'><dt id='V05U7'><q id='V05U7'><span id='V05U7'><b id='V05U7'><form id='V05U7'><ins id='V05U7'></ins><ul id='V05U7'></ul><sub id='V05U7'></sub></form><legend id='V05U7'></legend><bdo id='V05U7'><pre id='V05U7'><center id='V05U7'></center></pre></bdo></b><th id='V05U7'></th></span></q></dt></tr></i><div id='V05U7'><tfoot id='V05U7'></tfoot><dl id='V05U7'><fieldset id='V05U7'></fieldset></dl></div>
            <tbody id='V05U7'></tbody>

              • <bdo id='V05U7'></bdo><ul id='V05U7'></ul>
              • <legend id='V05U7'><style id='V05U7'><dir id='V05U7'><q id='V05U7'></q></dir></style></legend>

                  <small id='V05U7'></small><noframes id='V05U7'>

                1. 本文介绍了用于测试和主要的不同 Maven 编译器版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何配置 maven 编译器以使用 java 5 作为我的测试代码和 java 1.4 作为我的主要代码?

                  How can I configure the maven compiler to use java 5 for my test code and java 1.4 for my main code?

                  推荐答案

                  如果要设置符合相关Java版本,可以为每次执行配置编译器插件.假设 Maven 使用的 JDK 至少与您指定的最高版本一样最新.通过使用属性,您可以在命令行上覆盖该配置,如果需要,可以在子级中覆盖该配置:

                  If you want to set compliance to the relevant Java version, you can configure the compiler plugin for each execution. Assuming Maven is using a JDK at least as current as the highest version you specify. By using properties you can override that configuration on the commandline or in a child if needed:

                  <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 中定义它们

                  If you mean using different compilers, that's a bit more involved. as you need to specify the path to the JDK and what compiler version you're using. Again these can be defined in properties. Though you may want to define them in your 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 配置一个配置文件,这样您的正常构建就不会依赖于设置的属性.

                  Note it might make sense to define the compiler configurations in profiles, one for each JDK you support, so that your normal builds don't rely on properties being set.

                  另外,在 Maven 3.x 中,您需要在指定可执行文件时包含 fork 参数, 例如:

                  Also, in Maven 3.x, you need to include the fork parameter when specifying the executable, e.g.:

                    <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>
                  

                  这篇关于用于测试和主要的不同 Maven 编译器版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Compiling C++ for the JVM(为 JVM 编译 C++)
                  Compile to java bytecode (without using Java)(编译成java字节码(不使用Java))
                  How to drive C#, C++ or Java compiler to compute 1+2+3+...+1000 at compile time?(如何在编译时驱动 C#、C++ 或 Java 编译器计算 1+2+3+...+1000?)
                  Java ClassLoader: load same class twice(Java ClassLoader:两次加载相同的类)
                  How to debug .class files in ECLIPSE?(如何在 ECLIPSE 中调试 .class 文件?)
                  Java quot;The blank final field may not have been initializedquot; Anonymous Interface vs Lambda Expression(Java“可能尚未初始化空白的最终字段匿名接口与 Lambda 表达式)

                        <tbody id='1qFB8'></tbody>

                        <small id='1qFB8'></small><noframes id='1qFB8'>

                        <tfoot id='1qFB8'></tfoot>
                          • <bdo id='1qFB8'></bdo><ul id='1qFB8'></ul>
                            <i id='1qFB8'><tr id='1qFB8'><dt id='1qFB8'><q id='1qFB8'><span id='1qFB8'><b id='1qFB8'><form id='1qFB8'><ins id='1qFB8'></ins><ul id='1qFB8'></ul><sub id='1qFB8'></sub></form><legend id='1qFB8'></legend><bdo id='1qFB8'><pre id='1qFB8'><center id='1qFB8'></center></pre></bdo></b><th id='1qFB8'></th></span></q></dt></tr></i><div id='1qFB8'><tfoot id='1qFB8'></tfoot><dl id='1qFB8'><fieldset id='1qFB8'></fieldset></dl></div>
                          • <legend id='1qFB8'><style id='1qFB8'><dir id='1qFB8'><q id='1qFB8'></q></dir></style></legend>