使用Maven的Spring Boot应用程序构建遇到Java版本问题

时间:2018-06-09 15:07:27

标签: spring maven spring-boot maven-release-plugin

我正在尝试使用maven build构建一个应用程序。即使我已经将我的pom.xml文件放置到位,它也会返回此构建失败。 我已经配置了我的pom没有任何问题。但我可以看到有一些错误返回与schema相关。但是没有太多关于那个的信息

[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.amazon:amazon:jar:0.0.1-SNAPSHOT
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.springframework.boot:spring-boot-starter-test:jar -> duplicate declaration of version (?) @ line 65, column 15
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building MyApplication 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ amazon ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ amazon ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 6 source files to /Users/Arun/Documents/SpringBoot/MyApplication/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.051 s
[INFO] Finished at: 2018-06-09T08:00:55-07:00
[INFO] Final Memory: 25M/220M
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "pom.xml" could not be activated because it does not exist.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project amazon: Fatal error compiling: invalid target release: 1.8.0_73 -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

以下是我目前正在使用的pom.xml。

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.amazon</groupId>
    <artifactId>amazon</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>MyApplication</name>
    <description>Demo project</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8.0_73</java.version>
        <start-class>com.amazon.service.MyApplication</start-class>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jersey</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-rest-hal-browser</artifactId>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.apache.tomcat.embed/tomcat-embed-jasper -->
        <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.projectreactor</groupId>
            <artifactId>reactor-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.restdocs</groupId>
            <artifactId>spring-restdocs-mockmvc</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa -->
        <dependency>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

5 个答案:

答案 0 :(得分:1)

根据您的日志:

JAVA_HOME

您可能正在使用劣质JDK版本(例如1.7)将项目编译为更高的目标版本(在您的情况下为1.8.0_73)。

尝试安装JDK 1.8并使pom.xml环境变量指向它。

通常,您应确保源JDK和目标JDK在您的JAVA_HOME文件和{{1}}环境变量之间匹配。

答案 1 :(得分:0)

您可以尝试maven编译器插件

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.6.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

答案 2 :(得分:0)

删除添加的重复依赖项

        <artifactId>spring-boot-starter-test</artifactId>

和 尝试在项目构建路径中指向JDK 1.8,并将JAVA_HOME环境设置为此

答案 3 :(得分:0)

通常,pom.xml中未配置次要版本号(对于java)。只需要主要版本号。 尝试将 1.8.0_73 更改为 1.8

要了解java版本系统,请访问此link

答案 4 :(得分:0)

查看您的 maven 输出,很明显您有重复的依赖声明。此外,很明显,重复依赖项是 org.springframework.boot:spring-boot-starter-test

解决问题和消除此警告的过程是什么:

  1. 非常仔细查看您的 pom.xml。您可能已经声明了两次依赖项。
  2. 此警告的另一个原因可能是依赖项声明了两次,但版本不同。同样,解决方案是删除其中之一的依赖项。
  3. 命令 mvn dependency:tree -Dverbose 可能有用。

最后,写完上面的流程后,我查看了你贴在你问题中的pom.xml文件,发现你已经声明了两次如下依赖(line:54和line:65)。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
</dependency>

就我而言,这个库仅用于测试目的。如果这是真的,根据您的要求,您应该只保留第 54 行中的依赖项,警告将被删除。