Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在pom.xml中定义maven.compiler时遇到一些问题_Java_Maven - Fatal编程技术网

Java 在pom.xml中定义maven.compiler时遇到一些问题

Java 在pom.xml中定义maven.compiler时遇到一些问题,java,maven,Java,Maven,A)总结问题 pom maven中有三种定义编译器版本的方法。 我没有提到maven.compiler的发布、插件和版本(意味着maven构建成功),然后它是如何选择编译器版本的,我没有提到版本 关于我尝试过的东西,请参考b部分 (一) 1.8 1.8 org.apache.maven.plugins maven编译器插件 3.8.1 1.8 1.8 真的 8 B)我尝试过的 我删除了maven.compiler版本和它的工作插件,然后它如何选择编译器版本 <project

A)总结问题

pom maven中有三种定义编译器版本的方法。 我没有提到maven.compiler的发布、插件和版本(意味着maven构建成功),然后它是如何选择编译器版本的,我没有提到版本

关于我尝试过的东西,请参考b部分

(一)

1.8
1.8
  • 
    org.apache.maven.plugins
    maven编译器插件
    3.8.1 
    1.8
    1.8
    真的
    
  • 8
    
    B)我尝试过的

    我删除了maven.compiler版本和它的工作插件,然后它如何选择编译器版本

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>io.flowing.retail</groupId>
        <artifactId>flowing-retail-kafka-shipping</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <maven.compiler.source>1.8</maven.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
    
            <spring.boot.version>2.2.5.RELEASE</spring.boot.version>
            <spring-cloud-stream.version>Horsham.RELEASE</spring-cloud-stream.version>
        </properties>
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-dependencies</artifactId>
                    <version>${spring.boot.version}</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
                <dependency>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-stream-dependencies</artifactId>
                    <version>${spring-cloud-stream.version}</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-stream-kafka</artifactId>
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-web</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <!-- required to add JSR310 time formats for Jackson to ObjectMapper -->
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-json</artifactId>
            </dependency>
        </dependencies>
        <build>
            <plugins>
                 <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>              
                    <configuration>                         
                          <mainClass>io.flowing.retail.shipping.ShippingApplication</mainClass>
                    </configuration>
                 </plugin>
                 <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <executions>
                        <execution>
                          <goals>
                            <goal>repackage</goal>
                          </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </project>
    
    
    4.0.0
    零售业
    流动零售卡夫卡航运
    0.0.1-快照
    UTF-8
    1.8
    1.8
    2.2.5.1发布
    霍沙姆释放
    org.springframework.boot
    spring启动依赖项
    ${spring.boot.version}
    聚甲醛
    进口
    org.springframework.cloud
    spring云流依赖性
    ${spring cloud stream.version}
    聚甲醛
    进口
    org.springframework.cloud
    春云溪卡夫卡
    org.springframework.boot
    SpringBootStarterWeb
    org.springframework.boot
    spring启动程序json
    org.codehaus.mojo
    execmaven插件
    io.Flow.retail.shipping应用程序
    org.springframework.boot
    springbootmaven插件
    重新包装
    
  • 我定义了无效的maven.compiler.release。然后它也会起作用

    4.0.0 零售业 流动零售卡夫卡航运 0.0.1-快照 108 UTF-8 1.8 1.8

    2.2.5.1版本
    霍沙姆释放
    org.springframework.boot
    spring启动依赖项
    ${spring.boot.version}
    聚甲醛
    进口
    org.springframework.cloud
    spring云流依赖性
    ${spring cloud stream.version}
    聚甲醛
    进口
    org.springframework.cloud
    春云溪卡夫卡
    org.springframework.boot
    SpringBootStarterWeb
    org.springframework.boot
    spring启动程序json
    org.codehaus.mojo
    execmaven插件
    io.Flow.retail.shipping应用程序
    org.springframework.boot
    springbootmaven插件
    重新包装
    

  • [首先让我澄清您在问题中使用的表达式“选择编译器版本”。您使用的编译器是通过
    compilerId
    compilerVersion
    选项配置的,通常是您安装的JDK的编译器。我们正在讨论设置编译器的兼容性选项。]

    您提到的属性用于向
    javac
    编译器提供
    -source
    -target
    -release
    参数(如果使用其他编译器,则提供等效参数)

    由于
    --release
    是在Java9中引入的,因此应用哪种版本取决于用于运行maven的JDK。如果提供
    --release
    参数:

    • 在JDK 9及更高版本上,maven将忽略
      -source
      -target
      参数
    • 在JDK 8及更低版本上,编译将失败得很惨
    maven编译器插件指定了三种提供这些参数的方法:

  • 标记的
    部分。这一个凌驾于其他的之上
  • 作为
    pom.xml
    中的属性。如果未在
    部分中指定参数,则此选项适用
  • 如果未指定上述任何一项,则应用
    -source
    -target
    的默认值(
    --release
    没有默认值)
  • 您可以在
    maven编译器plugin.jar
    中找到默认值(参考资料
    META-INF/maven/plugin.xml
    ):

    
    ...
    ${maven.compiler.release}
    ...
    ${maven.compiler.source}
    ...
    ${maven.compiler.target}
    
    因此,由于您使用的是插件的版本
    3.8.1
    ,如果您根本没有指定任何内容,那么Java 6将适用

    TL;DR:如果您使用Java 9及更高版本,您的配置选项将按顺序3、2、1应用

    编辑:如果您的编译器支持它,请在设置
                <plugin> 
                <groupId>org.apache.maven.plugins</groupId> 
                <artifactId>maven-compiler-plugin</artifactId> 
                <version>3.8.1</version> 
                <configuration> 
                    <source>1.8</source> 
                    <target>1.8</target> 
                    <verbose>true</verbose> 
                </configuration> 
        </plugin>
    
    <maven.compiler.release> 8</maven.compiler.release>
    
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <groupId>io.flowing.retail</groupId>
        <artifactId>flowing-retail-kafka-shipping</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <maven.compiler.source>1.8</maven.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
    
            <spring.boot.version>2.2.5.RELEASE</spring.boot.version>
            <spring-cloud-stream.version>Horsham.RELEASE</spring-cloud-stream.version>
        </properties>
        <dependencyManagement>
            <dependencies>
                <dependency>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-dependencies</artifactId>
                    <version>${spring.boot.version}</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
                <dependency>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-stream-dependencies</artifactId>
                    <version>${spring-cloud-stream.version}</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
            </dependencies>
        </dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-stream-kafka</artifactId>
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-web</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <!-- required to add JSR310 time formats for Jackson to ObjectMapper -->
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-json</artifactId>
            </dependency>
        </dependencies>
        <build>
            <plugins>
                 <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>exec-maven-plugin</artifactId>              
                    <configuration>                         
                          <mainClass>io.flowing.retail.shipping.ShippingApplication</mainClass>
                    </configuration>
                 </plugin>
                 <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <executions>
                        <execution>
                          <goals>
                            <goal>repackage</goal>
                          </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </project>
    
             <spring.boot.version>2.2.5.RELEASE</spring.boot.version>
             <spring-cloud-stream.version>Horsham.RELEASE</spring-cloud-stream.version>
         </properties>
         <dependencyManagement>
             <dependencies>
                 <dependency>
                     <groupId>org.springframework.boot</groupId>
                     <artifactId>spring-boot-dependencies</artifactId>
                     <version>${spring.boot.version}</version>
                     <type>pom</type>
                     <scope>import</scope>
                 </dependency>
                 <dependency>
                     <groupId>org.springframework.cloud</groupId>
                     <artifactId>spring-cloud-stream-dependencies</artifactId>
                     <version>${spring-cloud-stream.version}</version>
                     <type>pom</type>
                     <scope>import</scope>
                 </dependency>
             </dependencies>
         </dependencyManagement>
         <dependencies>
             <dependency>
                 <groupId>org.springframework.cloud</groupId>
                 <artifactId>spring-cloud-starter-stream-kafka</artifactId>
                 <exclusions>
                     <exclusion>
                         <groupId>org.springframework.boot</groupId>
                         <artifactId>spring-boot-starter-web</artifactId>
                     </exclusion>
                 </exclusions>
             </dependency>
             <dependency>
                 <!-- required to add JSR310 time formats for Jackson to ObjectMapper -->
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-starter-json</artifactId>
             </dependency>
         </dependencies>
         <build>
             <plugins>
                  <plugin>
                     <groupId>org.codehaus.mojo</groupId>
                     <artifactId>exec-maven-plugin</artifactId>              
                     <configuration>                         
                           <mainClass>io.flowing.retail.shipping.ShippingApplication</mainClass>
                     </configuration>
                  </plugin>
                  <plugin>
                     <groupId>org.springframework.boot</groupId>
                     <artifactId>spring-boot-maven-plugin</artifactId>
                     <executions>
                         <execution>
                           <goals>
                             <goal>repackage</goal>
                           </goals>
                         </execution>
                     </executions>
                 </plugin>
             </plugins>
         </build>
     </project>