无法构建gradle项目:无效的类型代码:使用Java 11的B3

时间:2019-07-01 00:47:23

标签: java gradle intellij-idea

我正在将Java 11用于该项目。 Gradle版本是5.5。 IntelijIDEA 2019.1.3

因此,在构建项目时,出现错误:

Cause: invalid type code: B3

Stacktrace显示给我:

org.gradle.internal.exceptions.LocationAwareException: Build file 'D:\project\scripts\build.gradle' line: 21
A problem occurred evaluating project ':scripts'.
    at org.gradle.initialization.exception.DefaultExceptionAnalyser.transform(DefaultExceptionAnalyser.java:99)
    at org.gradle.initialization.exception.DefaultExceptionAnalyser.collectFailures(DefaultExceptionAnalyser.java:55)
    at org.gradle.initialization.exception.MultipleBuildFailuresExceptionAnalyser.transform(MultipleBuildFailuresExceptionAnalyser.java:47)
    at org.gradle.initialization.exception.StackTraceSanitizingExceptionAnalyser.transform(StackTraceSanitizingExceptionAnalyser.java:29)

命令gradle task dev update告诉我:

* What went wrong:
A problem occurred evaluating project ':scripts'.
> Could not find method leftShift() for arguments [build_44ncodnspa3jbc57fnmmpuh13$_run_closure1@4c5511e6] on task ':scripts:dev' of type org.gradle.api.DefaultTask.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED

build.gradle文件代码中,给我错误的是:

task("dev") << {
    println "executing dev"
    liquibase {
        activities {
            main {
                changeLogFile changeLog
                classpath "$projectDir/src/main/resources/"
                url 'jdbc:postgresql://localhost:5432/project'
                username 'testName'
                password 'testPassword'
                liquibaseSchemaName 'liquibase'
            }
        }
    }
}

我在unticking the flag Settings -> Experimental -> Only sync the active variant中使用了解决方案。

但是我可以在不更改IntelijIDEA设置的情况下通过代码解决问题吗? 因为syncing the project作为优化过程很重要。尤其是大型项目。

1 个答案:

答案 0 :(得分:0)

在分析并找到updated syntax之后,我将内容更改为:

task("dev") {
    doLast {
        println "executing dev"
        liquibase {
            activities {
                main {
                    changeLogFile changeLog
                    classpath "$projectDir/src/main/resources/"
                    url 'jdbc:postgresql://localhost:5432/project'
                    username 'testName'
                    password 'testPassword'
                    liquibaseSchemaName 'liquibase'
                }
            }
        }
    }
}

最终,更新的代码帮助我解决了问题,而无需使用IntelijIDEA的设置。

gradle task dev update成功运行。