【问题标题】:Spring boot App - Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile on ProjectSpring boot App - 无法在项目上执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile
【发布时间】:2020-06-11 14:21:24
【问题描述】:

我正在尝试在 Heroku 上部署一个 Spring Boot 应用程序。这是我的 heroku 错误日志:

remote:        [ERROR] COMPILATION ERROR : 
remote:        [INFO] -------------------------------------------------------------
remote:        [ERROR] /tmp/build_ffefd73b56c7017473a0b98cce9d815d/src/test/java/com/ticketbooking/ticketbooking/TicketbookingApplicationTests.java:[3,29] package org.junit.jupiter.api does not exist
remote:        [ERROR] /tmp/build_ffefd73b56c7017473a0b98cce9d815d/src/test/java/com/ticketbooking/ticketbooking/TicketbookingApplicationTests.java:[4,45] package org.springframework.boot.test.context does not exist
remote:        [ERROR] /tmp/build_ffefd73b56c7017473a0b98cce9d815d/src/test/java/com/ticketbooking/ticketbooking/TicketbookingApplicationTests.java:[6,2] cannot find symbol
remote:          symbol: class SpringBootTest
remote:        [ERROR] /tmp/build_ffefd73b56c7017473a0b98cce9d815d/src/test/java/com/ticketbooking/ticketbooking/TicketbookingApplicationTests.java:[9,6] cannot find symbol
remote:          symbol:   class Test
remote:          location: class com.ticketbooking.ticketbooking.TicketbookingApplicationTests
remote:        [INFO] 4 errors 
remote:        [INFO] -------------------------------------------------------------
remote:        [INFO] ------------------------------------------------------------------------
remote:        [INFO] BUILD FAILURE

我很困惑,因为我没有任何测试类,我不知道它从哪里获得 TicketbookingApplicationTests 类。

这是我的 pom.xml:

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

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jdbc</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
        <groupId>org.postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>42.2.10</version>
    </dependency>

    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-core</artifactId>
        <version>2.11.2</version>
        <type>pom</type>
    </dependency>

    <dependency>
        <groupId>com.fasterxml.jackson.datatype</groupId>
        <artifactId>jackson-datatype-jsr310</artifactId>
        <version>2.10.2</version>
    </dependency>

    <!-- API, java.xml.bind module -->
    <dependency>
        <groupId>jakarta.xml.bind</groupId>
        <artifactId>jakarta.xml.bind-api</artifactId>
        <version>2.3.2</version>
    </dependency>

    <!-- Runtime, com.sun.xml.bind module -->
    <dependency>
        <groupId>org.glassfish.jaxb</groupId>
        <artifactId>jaxb-runtime</artifactId>
        <version>2.3.2</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.2.11.Final</version>
    </dependency>

    <dependency>
        <groupId>com.google.zxing</groupId>
        <artifactId>javase</artifactId>
        <version>3.3.0</version>
    </dependency>

    <dependency>
        <groupId>org.mindrot</groupId>
        <artifactId>jbcrypt</artifactId>
        <version>0.3m</version>
    </dependency>
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.5</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-security -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
        <version>2.2.2.RELEASE</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/io.jsonwebtoken/jjwt -->
    <dependency>
        <groupId>io.jsonwebtoken</groupId>
        <artifactId>jjwt</artifactId>
        <version>0.2</version>
    </dependency>

</dependencies>

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

    </plugins>
</build>

【问题讨论】:

    标签: spring-boot heroku maven-compiler-plugin


    【解决方案1】:

    如果您没有找到这些类,请尝试构建跳过测试步骤:

    mvn install -DskipTests
    

    【讨论】:

    • 我认为 heroku 在您尝试部署时使用 --DskipTests 选项:“git push heroku master”,它运行“./mvnw -DskipTests clean dependency:list install”
    【解决方案2】:

    我解决了这个问题: How can I reconcile detached HEAD with master/origin?

    我的 git 处于与 origin/master 分离的 HEAD 状态,其中包含一些 junit 测试。

    【讨论】:

      【解决方案3】:

      Heroku 必须知道您的项目中使用的是哪个 JDK 版本(我的系统的 JDK 版本是 11)。将以下行添加到 system.properties 文件。如果该文件不存在,则在项目根目录下创建它。用你的替换 11。

      java.runtime.version=11
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-09-02
        • 2021-03-11
        • 2020-07-29
        • 2018-03-04
        • 2016-08-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多