isBlank() 在本地工作,但是在推送到 heroku 时:找不到符号

Posted

技术标签:

【中文标题】isBlank() 在本地工作,但是在推送到 heroku 时:找不到符号【英文标题】:isBlank() working locally, but when pushing to heroku: cannot find symbol 【发布时间】:2021-10-20 09:27:31 【问题描述】:

我有一个在 localhost:8080 设置中运行的项目。我对 Heroku 和 git bash 以及所有这些实际上都很陌生。

将我的项目推送到 Heroku 时出现以下错误:

remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpack: heroku/java
remote: -----> Java app detected
remote: -----> Installing JDK 1.8... done
remote: -----> Installing Maven 3.6.2... done
remote: -----> Executing Maven
remote:        $ mvn -DskipTests clean dependency:list install
remote:        [INFO] Scanning for projects...
remote:        [INFO]
remote:        [INFO] -------------------------< tkt:wepa_Projekti >--------------------------
remote:        [INFO] Building wepa_Projekti 1.0-SNAPSHOT
remote:        [INFO] --------------------------------[ jar ]---------------------------------
remote:        [INFO] Downloading from tmc: https://maven.mooc.fi/releases/org/passay/passay/1.6.0/passay-1.6.0.pom
remote:        [INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/passay/passay/1.6.0/passay-1.6.0.pom
remote:        [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/passay/passay/1.6.0/passay-1.6.0.pom (15 kB at 148 kB/s)
remote:        [INFO] Downloading from tmc: https://maven.mooc.fi/releases/org/springframework/boot/spring-boot-starter-validation/2.3.2.RELEASE/spring-boot-starter-validation-2.3.2.RELEASE.pom
remote:        [INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-validation/2.3.2.RELEASE/spring-boot-starter-validation-2.3.2.RELEASE.pom
remote:        [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-validation/2.3.2.RELEASE/spring-boot-starter-validation-2.3.2.RELEASE.pom (2.5 kB at 121 kB/s)
remote:        [INFO] Downloading from tmc: https://maven.mooc.fi/releases/org/hibernate/validator/hibernate-validator/6.1.5.Final/hibernate-validator-6.1.5.Final.pom
remote:        [INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/hibernate/validator/hibernate-validator/6.1.5.Final/hibernate-validator-6.1.5.Final.pom
remote:        [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/hibernate/validator/hibernate-validator/6.1.5.Final/hibernate-validator-6.1.5.Final.pom (13 kB at 1.0 MB/s)
remote:        [INFO] Downloading from tmc: https://maven.mooc.fi/releases/org/hibernate/validator/hibernate-validator-parent/6.1.5.Final/hibernate-validator-parent-6.1.5.Final.pom
remote:        [INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/hibernate/validator/hibernate-validator-parent/6.1.5.Final/hibernate-validator-parent-6.1.5.Final.pom
remote:        [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/hibernate/validator/hibernate-validator-parent/6.1.5.Final/hibernate-validator-parent-6.1.5.Final.pom (67 kB at 2.0 MB/s)
remote:        [INFO] Downloading from tmc: https://maven.mooc.fi/releases/org/jboss/arquillian/arquillian-bom/1.1.11.Final/arquillian-bom-1.1.11.Final.pom
remote:        [INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/jboss/arquillian/arquillian-bom/1.1.11.Final/arquillian-bom-1.1.11.Final.pom
remote:        [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/jboss/arquillian/arquillian-bom/1.1.11.Final/arquillian-bom-1.1.11.Final.pom (11 kB at 967 kB/s)
remote:        [INFO] Downloading from tmc: https://maven.mooc.fi/releases/org/jboss/shrinkwrap/shrinkwrap-bom/1.2.3/shrinkwrap-bom-1.2.3.pom
remote:        [INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/jboss/shrinkwrap/shrinkwrap-bom/1.2.3/shrinkwrap-bom-1.2.3.pom
remote:        [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/jboss/shrinkwrap/shrinkwrap-bom/1.2.3/shrinkwrap-bom-1.2.3.pom (4.0 kB at 443 kB/s)
remote:        [INFO] Downloading from tmc: https://maven.mooc.fi/releases/org/jboss/shrinkwrap/resolver/shrinkwrap-resolver-bom/2.2.0/shrinkwrap-resolver-bom-2.2.0.pom
remote:        [INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/jboss/shrinkwrap/resolver/shrinkwrap-resolver-bom/2.2.0/shrinkwrap-resolver-bom-2.2.0.pom
remote:        [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/jboss/shrinkwrap/resolver/shrinkwrap-resolver-bom/2.2.0/shrinkwrap-resolver-bom-2.2.0.pom (5.3 kB at 331 kB/s)
remote:        [INFO] Downloading from tmc: https://maven.mooc.fi/releases/org/jboss/shrinkwrap/descriptors/shrinkwrap-descriptors-bom/2.0.0-alpha-8/shrinkwrap-descriptors-bom-2.0.0-alpha-8.pom
remote:        [INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/jboss/shrinkwrap/descriptors/shrinkwrap-descriptors-bom/2.0.0-alpha-8/shrinkwrap-descriptors-bom-2.0.0-alpha-8.pom
remote:        [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/jboss/shrinkwrap/descriptors/shrinkwrap-descriptors-bom/2.0.0-alpha-8/shrinkwrap-descriptors-bom-2.0.0-alpha-8.pom (5.2 kB at 582 kB/s)
remote:        [INFO] Downloading from tmc: https://maven.mooc.fi/releases/jakarta/validation/jakarta.validation-api/2.0.2/jakarta.validation-api-2.0.2.pom
remote:        [INFO] Downloading from central: https://repo.maven.apache.org/maven2/jakarta/validation/jakarta.validation-api/2.0.2/jakarta.validation-api-2.0.2.pom
remote:        [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/jakarta/validation/jakarta.validation-api/2.0.2/jakarta.validation-api-2.0.2.pom (11 kB at 1.3 MB/s)
remote:        [INFO] Downloading from tmc: https://maven.mooc.fi/releases/ognl/ognl/3.1.12/ognl-3.1.12.jar
remote:        [INFO] Downloading from tmc: https://maven.mooc.fi/releases/org/springframework/boot/spring-boot-starter-validation/2.3.2.RELEASE/spring-boot-starter-validation-2.3.2.RELEASE.jar
remote:        [INFO] Downloading from tmc: https://maven.mooc.fi/releases/org/hibernate/validator/hibernate-validator/6.1.5.Final/hibernate-validator-6.1.5.Final.jar
remote:        [INFO] Downloading from tmc: https://maven.mooc.fi/releases/jakarta/validation/jakarta.validation-api/2.0.2/jakarta.validation-api-2.0.2.jar
remote:        [INFO] Downloading from tmc: https://maven.mooc.fi/releases/org/passay/passay/1.6.0/passay-1.6.0.jar
remote:        [INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/passay/passay/1.6.0/passay-1.6.0.jar
remote:        [INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-validation/2.3.2.RELEASE/spring-boot-starter-validation-2.3.2.RELEASE.jar
remote:        [INFO] Downloading from central: https://repo.maven.apache.org/maven2/org/hibernate/validator/hibernate-validator/6.1.5.Final/hibernate-validator-6.1.5.Final.jar
remote:        [INFO] Downloading from central: https://repo.maven.apache.org/maven2/ognl/ognl/3.1.12/ognl-3.1.12.jar
remote:        [INFO] Downloading from central: https://repo.maven.apache.org/maven2/jakarta/validation/jakarta.validation-api/2.0.2/jakarta.validation-api-2.0.2.jar
remote:        [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-validation/2.3.2.RELEASE/spring-boot-starter-validation-2.3.2.RELEASE.jar (4.8 kB at 58 kB/s)
remote:        [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/ognl/ognl/3.1.12/ognl-3.1.12.jar (236 kB at 2.1 MB/s)
remote:        [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/passay/passay/1.6.0/passay-1.6.0.jar (124 kB at 1.1 MB/s)
remote:        [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/jakarta/validation/jakarta.validation-api/2.0.2/jakarta.validation-api-2.0.2.jar (92 kB at 760 kB/s)
remote:        [INFO] Downloaded from central: https://repo.maven.apache.org/maven2/org/hibernate/validator/hibernate-validator/6.1.5.Final/hibernate-validator-6.1.5.Final.jar (1.3 MB at 5.7 MB/s)
remote:        [INFO]
remote:        [INFO] --- maven-clean-plugin:3.1.0:clean (default-clean) @ wepa_Projekti ---
remote:        [INFO]
remote:        [INFO] --- maven-dependency-plugin:3.1.2:list (default-cli) @ wepa_Projekti ---
remote:        [INFO]
remote:        [INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ wepa_Projekti ---
remote:        [INFO] Using 'UTF-8' encoding to copy filtered resources.
remote:        [INFO] Copying 4 resources
remote:        [INFO] Copying 21 resources
remote:        [INFO]
remote:        [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ wepa_Projekti ---
remote:        [INFO] Changes detected - recompiling the module!
remote:        [INFO] Compiling 44 source files to /tmp/build_b0fadb36/target/classes
remote:        [INFO] /tmp/build_b0fadb36/src/main/java/projekti/CustomErrorController.java: /tmp/build_b0fadb36/src/main/java/projekti/CustomErrorController.java uses or overrides a deprecated API.
remote:        [INFO] /tmp/build_b0fadb36/src/main/java/projekti/CustomErrorController.java: Recompile with -Xlint:deprecation for details.
remote:        [INFO] -------------------------------------------------------------
remote:        [ERROR] COMPILATION ERROR :
remote:        [INFO] -------------------------------------------------------------
remote:        [ERROR] /tmp/build_b0fadb36/src/main/java/projekti/SaunojaService.java:[154,120] cannot find symbol
remote:          symbol:   method isBlank()
remote:          location: class java.lang.String
remote:        [ERROR] /tmp/build_b0fadb36/src/main/java/projekti/NotificationService.java:[54,81] cannot find symbol
remote:          symbol:   method isBlank()
remote:          location: class java.lang.String
remote:        [ERROR] /tmp/build_b0fadb36/src/main/java/projekti/MessageService.java:[82,71] cannot find symbol
remote:          symbol:   method isBlank()
remote:          location: class java.lang.String
remote:        [ERROR] /tmp/build_b0fadb36/src/main/java/projekti/CommentService.java:[56,71] cannot find symbol
remote:          symbol:   method isBlank()
remote:          location: class java.lang.String
remote:        [ERROR] /tmp/build_b0fadb36/src/main/java/projekti/AccountFreezeService.java:[71,51] cannot find symbol
remote:          symbol:   method isBlank()
remote:          location: class java.lang.String
remote:        [INFO] 5 errors
remote:        [INFO] -------------------------------------------------------------
remote:        [INFO] ------------------------------------------------------------------------
remote:        [INFO] BUILD FAILURE
remote:        [INFO] ------------------------------------------------------------------------
remote:        [INFO] Total time:  12.772 s
remote:        [INFO] Finished at: 2021-08-18T14:35:20Z
remote:        [INFO] ------------------------------------------------------------------------
remote:        [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project wepa_Projekti: Compilation failure: Compilation failure:
remote:        [ERROR] /tmp/build_b0fadb36/src/main/java/projekti/SaunojaService.java:[154,120] cannot find symbol
remote:        [ERROR]   symbol:   method isBlank()
remote:        [ERROR]   location: class java.lang.String
remote:        [ERROR] /tmp/build_b0fadb36/src/main/java/projekti/NotificationService.java:[54,81] cannot find symbol
remote:        [ERROR]   symbol:   method isBlank()
remote:        [ERROR]   location: class java.lang.String
remote:        [ERROR] /tmp/build_b0fadb36/src/main/java/projekti/MessageService.java:[82,71] cannot find symbol
remote:        [ERROR]   symbol:   method isBlank()
remote:        [ERROR]   location: class java.lang.String
remote:        [ERROR] /tmp/build_b0fadb36/src/main/java/projekti/CommentService.java:[56,71] cannot find symbol
remote:        [ERROR]   symbol:   method isBlank()
remote:        [ERROR]   location: class java.lang.String
remote:        [ERROR] /tmp/build_b0fadb36/src/main/java/projekti/AccountFreezeService.java:[71,51] cannot find symbol
remote:        [ERROR]   symbol:   method isBlank()
remote:        [ERROR]   location: class java.lang.String
remote:        [ERROR] -> [Help 1]
remote:        [ERROR]
remote:        [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
remote:        [ERROR] Re-run Maven using the -X switch to enable full debug logging.
remote:        [ERROR]
remote:        [ERROR] For more information about the errors and possible solutions, please read the following articles:
remote:        [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
remote:
remote:  !     ERROR: Failed to build app with Maven
remote:        We're sorry this build is failing! If you can't find the issue in application code,
remote:        please submit a ticket so we can help: https://help.heroku.com/

我的 Java 版本:

$ java -version
openjdk version "11.0.9.1" 2020-11-04
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.9.1+1)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.9.1+1, mixed mode)

似乎问题可能出在项目的依赖关系上,但我不明白的是,为什么问题不会在本地发生。

项目 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>tkt</groupId>
    <artifactId>wepa_Projekti</artifactId>
    <name>wepa_Projekti</name>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    
    <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>
    </properties>
    
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.2.RELEASE</version>
        <relativePath/>
    </parent>

    <dependencies>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.thymeleaf.extras</groupId>
            <artifactId>thymeleaf-extras-springsecurity5</artifactId>
        </dependency>
        <dependency>
            <groupId>org.thymeleaf.extras</groupId>
            <artifactId>thymeleaf-extras-java8time</artifactId>
            <version>3.0.4.RELEASE</version>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
        </dependency>        
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <scope>provided</scope>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>
        
        <dependency>
            <groupId>org.passay</groupId>
            <artifactId>passay</artifactId>
            <version>1.6.0</version>
        </dependency>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-validation</artifactId>
        </dependency>
        
        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
        </dependency>
        
        <dependency>
            <groupId>org.fluentlenium</groupId>
            <artifactId>fluentlenium-junit</artifactId>
            <version>3.7.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.fluentlenium</groupId>
            <artifactId>fluentlenium-assertj</artifactId>
            <version>3.7.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>htmlunit-driver</artifactId>
        </dependency>  
                        
        <!-- TMC -->
        <dependency>
            <groupId>fi.helsinki.cs.tmc</groupId>
            <artifactId>edu-test-utils</artifactId>
            <version>0.4.2</version>
            <scope>test</scope>
        </dependency>
    
    </dependencies>

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

    <repositories>
        <repository>
            <id>tmc</id>
            <name>TMC repo</name>
            <url>https://maven.mooc.fi/releases</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>tmc</id>
            <name>TMC repo</name>
            <url>https://maven.mooc.fi/releases</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
</project>

【问题讨论】:

我可以在上面看到您已经安装了 JDK 1.8。这个版本没有isBlank()。为此,您至少需要 Java 11。 heroku 使用的版本可能与命令行不同,因此您应该检查一下。 感谢您的快速答复!我确实似乎安装了1.8版本。但为什么?会不会是 1.8 的 maven.compiler.source 和 .target 导致了这种情况? 我会这么说。您是否测试过将其更改为 Java 11? Heroku documentation 声明您应该添加一个文件“system.properties”,指定 Heroku 应该使用的所需 Java 版本:“java.runtime.version=11” 您好,再次感谢您的评论。我尝试将 maven.compiler.source 和 .target 更改为 1.11,然后更改为 11。两者都给出了一个新错误:“Fatal error compile: invalid target release: 11(or 1.11)”。此外,在推送到 Herkoku 时,使用 Thomas 提到的行添加 system.properties 文件并没有将安装的 JDK 版本从 1.8 更改。 【参考方案1】:

很抱歉通知您,但有一个与 Muhammad Shah 的有效答案几乎相同的问题:Heroku cannot deploy Java 11 Spring Boot App。

答案仍然与 Thomas Kläger 在这里给出的相同。我的错误是我在资源文件夹中创建了 system.proterties 文件,但它应该位于根目录中。

感谢所有回答和评论的人!

【讨论】:

【参考方案2】:

我无法发表评论,所以我将其作为答案:

您似乎在 Java 1.8 版本上使用 Java 11+ 功能。确保您的 IDE 可以使用 Java 11 JDK(例如在 Eclipse 中查看如何设置 here)。

然后,在您的 .pom 文件中,更改:

<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

到:

<properties>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
</properties>

这将使 Maven 将您的项目编译为 Java 11 而不是 Java 8。也许您需要更新您的 Maven 版本,以便它可以正确识别 Java 11。

【讨论】:

我都试过了。将 maven.compiler.source 和 .target 更改为 11 时,我收到一个新错误:“致命错误编译:无效的目标版本:11”。我正要想出一个 java 1.8 的方法来做 isBlank() .. 女巫很可怜 :( 检查“mvn --version”时,我得到:Apache Maven 3.8.1 和 Java 版本 11.0.9.1 你是用mvn命令行工具编译还是用Eclipse之类的IDE? mvn --version 的输出与使用 IDE 无关。确保正确配置 IDE 以使用 Java 11 JDK 我在本地使用 Netbeans,一切正常。但是当使用 Git Bash 推送到 Heroku 时,就会出现错误。

以上是关于isBlank() 在本地工作,但是在推送到 heroku 时:找不到符号的主要内容,如果未能解决你的问题,请参考以下文章

Mongodb atlas + node.js 在本地工作,但在推送到 Heroku 时停止

Linux 上的多个 github 帐户 - 无法推送到远程,但可以拉取

TortoiseGit- 创建本地新分支,提交推送到远程,本地新分支合并到工作分支,提交到远程工作分支等。

在codeigniter中将json数据推送到数据库

如何将本地git存储库推送到svn

本地代码推送到Coding