maven-compiler-plugin:3.1:编译(默认编译)

问题描述 投票:0回答:1

怎么了?我不明白。 我正在尝试执行一个多模块项目,但由于此错误,我无法构建该项目。 我也在网上搜索过这个错误,但没有什么用处。谁能帮助我吗?

这是日志错误:

maven-compiler-plugin:3.1:compile (default-compile) on project api: Compilation failure: Compilation failure: [ERROR] Source option 5 is no longer supported. Use 7 or later. [ERROR] Target option 5 is no longer supported. Use 7 or later.

这是我的 pom 文件:

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>se.magnus.microservices.core.microservices-book</groupId>
    <artifactId>microservices-book</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <name>microservices-book</name>
    <packaging>pom</packaging>

    <properties>
        <java.version>17</java.version>
        <targetJdk>17</targetJdk>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <modules>
        <module>microservices</module>
        <module>api</module>
        <module>util</module>
    </modules>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <!-- Import dependency management from Spring Boot -->
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>3.1.0</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

</project>

我必须构建这个多模块项目

java maven build
1个回答
1
投票

默认 maven 使用 java 1.8 进行编译,因此您必须按如下方式配置您的 Maven 插件,将其添加到您的 pom 文件中:

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>se.magnus.microservices.core.microservices-book</groupId>
    <artifactId>microservices-book</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <name>microservices-book</name>
    <packaging>pom</packaging>

    <properties>
        <java.version>17</java.version>
        <targetJdk>17</targetJdk>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <modules>
        <module>microservices</module>
        <module>api</module>
        <module>util</module>
    </modules>

    <!-- add this --> 
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>17</source>
                        <target>17</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <!-- Import dependency management from Spring Boot -->
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>3.1.0</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

</project>
© www.soinside.com 2019 - 2024. All rights reserved.