任务“:compileGsonViews”的执行优化已被禁用

Execution optimizations have been disabled for task ':compileGsonViews'

我们最近将我们的项目从 Grails 3 升级到了 5.1.1。实际上,这不是真正的升级,而是迁移。我们最终使用 5.1.1 创建了一个新项目,并将我们所有的代码迁移到其中。目前一切正常,但有一个警告例外:

> Task :compileGsonViews
Execution optimizations have been disabled for task ':compileGsonViews' to ensure correctness due to the following reasons:
  - Gradle detected a problem with the following location: '/Users/shurikag/PRIZ/dev/priz-api/build/gson-classes/main'. Reason: Task ':bootWarMainClassName' uses this output of task ':compileGsonViews' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.3.3/userguide/validation_problems.html#implicit_dependency for more details about this problem.

事实上,正如我们的 newrelic 所示,应用程序现在在 gson 渲染上非常慢。通常第一次调用端点很慢,后面的调用都OK。

有解决办法吗?

这是我们的 build.gradle:

buildscript {
    repositories {
        maven {
            url "https://repo.grails.org/grails/core"
        }
        maven {
            url "https://repo.grails.org/artifactory/core"
        }
        mavenCentral()
    }
    dependencies {
        classpath "org.grails:grails-gradle-plugin:$grailsGradlePluginVersion"
        classpath "org.grails.plugins:hibernate5:7.2.0"
        classpath "org.grails.plugins:views-gradle:2.1.2"
        classpath "gradle.plugin.com.github.erdi.webdriver-binaries:webdriver-binaries-gradle-plugin:2.6"
        classpath 'org.grails.plugins:database-migration:3.1.0'
    }
}

version "0.1"
group "priz.api"

apply plugin: "eclipse"
apply plugin: "idea"
// apply plugin:"visual-studio"
apply plugin: "war"
apply plugin: "org.grails.grails-web"
apply plugin: "org.grails.plugins.views-json"
apply plugin: "com.github.erdi.webdriver-binaries"

repositories {
    maven {
        url "https://repo.grails.org/grails/core"
    }
    maven {
        url "https://repo.grails.org/artifactory/core"
    }
    mavenCentral()
}

configurations {
    developmentOnly
    runtimeClasspath {
        extendsFrom developmentOnly
    }
}

dependencies {
    implementation platform('com.amazonaws:aws-java-sdk-bom:1.11.1000')
    implementation 'com.amazonaws:aws-java-sdk-s3'
    developmentOnly("org.springframework.boot:spring-boot-devtools")
    compileOnly "io.micronaut:micronaut-inject-groovy"
    // https://mvnrepository.com/artifact/io.micronaut/micronaut-core
    implementation 'io.micronaut:micronaut-core:3.2.6'

    console "org.grails:grails-console"
    implementation "org.springframework.boot:spring-boot-starter-logging:2.6.2"
    implementation "org.springframework.boot:spring-boot-starter-validation:2.6.2"
    implementation "org.springframework.boot:spring-boot-autoconfigure:2.6.2"
    implementation "org.grails:grails-core"
    implementation "org.springframework.boot:spring-boot-starter-actuator:2.6.2"
    implementation "org.springframework.boot:spring-boot-starter-tomcat:2.6.2"
    implementation "org.grails:grails-plugin-url-mappings"
    implementation "org.grails:grails-plugin-rest"
    implementation "org.grails:grails-plugin-codecs"
    implementation "org.grails:grails-plugin-interceptors"
    implementation "org.grails:grails-plugin-services"
    implementation "org.grails:grails-plugin-datasource"
    implementation "org.grails:grails-plugin-databinding"
    implementation "org.grails:grails-web-boot"
    implementation "org.grails:grails-logging"
    implementation "org.grails.plugins:cache"
    implementation "org.grails.plugins:async"
    implementation "org.grails.plugins:events"
    implementation "org.grails.plugins:hibernate5"
    implementation "org.hibernate:hibernate-core:5.6.3.Final"
    implementation 'org.hibernate:hibernate-ehcache:5.6.3.Final'
    implementation "org.grails.plugins:views-json:2.1.2"
    implementation "org.grails.plugins:views-json-templates:2.1.2"
    profile "org.grails.profiles:rest-api"
    runtimeOnly "org.glassfish.web:el-impl:2.2.1-b05"
    runtimeOnly "com.h2database:h2"
    runtimeOnly "org.apache.tomcat:tomcat-jdbc"
    runtimeOnly "javax.xml.bind:jaxb-api:2.3.1"
    testImplementation "io.micronaut:micronaut-inject-groovy"
    testImplementation "org.grails:grails-gorm-testing-support"
    testImplementation "org.mockito:mockito-core"
    testImplementation "io.micronaut:micronaut-http-client"
    testImplementation "org.grails:grails-web-testing-support"
    testImplementation "org.grails:views-json-testing-support"
    testImplementation "org.hibernate.validator:hibernate-validator:6.1.7.Final"
    testImplementation "org.grails.plugins:geb"
    testImplementation "org.seleniumhq.selenium:selenium-remote-driver:4.0.0"
    testImplementation "org.seleniumhq.selenium:selenium-api:4.0.0"
    testImplementation "org.seleniumhq.selenium:selenium-support:4.0.0"
    testRuntimeOnly "org.seleniumhq.selenium:selenium-chrome-driver:4.0.0"
    testRuntimeOnly "org.seleniumhq.selenium:selenium-firefox-driver:4.0.0"
    runtimeOnly "org.grails.plugins:async:4.0.0"

    implementation 'org.grails.plugins:postgresql-extensions:7.0.0'
    implementation "org.postgresql:postgresql:42.3.1"
    implementation 'org.grails.plugins:database-migration:3.1.0'
    implementation 'org.liquibase:liquibase-core:3.10.3'

    implementation "org.grails.plugins:spring-security-core:4.0.3"
    implementation "org.grails.plugins:spring-security-rest:3.0.1"
    implementation 'com.auth0:auth0:1.35.0'
    implementation 'com.auth0:jwks-rsa:0.20.0'

    implementation 'com.sendinblue:sib-api-v3-sdk:5.2.0'

    implementation 'com.papertrailapp:logback-syslog4j:1.0.0'
    implementation "com.stripe:stripe-java:17.11.0"
    implementation "org.grails:grails-datastore-gorm-async"
    implementation 'org.quartz-scheduler:quartz:2.3.2'

    implementation 'com.squareup.okhttp3:okhttp:4.9.3'

    implementation 'co.elastic.clients:elasticsearch-java:7.16.2'
    implementation 'jakarta.json:jakarta.json-api:2.0.1'
    implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.3'
}

sourceSets {
    main {
        resources {
            srcDir 'grails-app/migrations'
        }
    }
}

bootRun {
    ignoreExitValue true
    jvmArgs(
            '-Dspring.output.ansi.enabled=always',
            '-noverify',
            '-XX:TieredStopAtLevel=1',
            '-Xmx1024m')
    sourceResources sourceSets.main
    String springProfilesActive = 'spring.profiles.active'
    systemProperty springProfilesActive, System.getProperty(springProfilesActive)
}

tasks.withType(GroovyCompile) {
    configure(groovyOptions) {
        forkOptions.jvmArgs = ['-Xmx1024m']
    }
}

tasks.withType(Test) {
    useJUnitPlatform()
}

webdriverBinaries {
    chromedriver '2.45.0'
    geckodriver '0.30.0'
}

tasks.withType(Test) {
    systemProperty "geb.env", System.getProperty('geb.env')
    systemProperty "geb.build.reportsDir", reporting.file("geb/integrationTest")
    systemProperty "webdriver.chrome.driver", System.getProperty('webdriver.chrome.driver')
    systemProperty "webdriver.gecko.driver", System.getProperty('webdriver.gecko.driver')
}

更新

重现新项目的步骤

~/PRIZ/dev $ grails -v
| Grails Version: 5.1.1
| JVM Version: 11.0.12
~/PRIZ/dev $ grails create-app myapp --profile=rest-api
| Application created at /Users/shurikag/PRIZ/dev/myapp
~/PRIZ/dev $ cd myapp
~/PRIZ/dev/myapp $ ./gradlew assemble
Starting a Gradle Daemon (subsequent builds will be faster)

> Task :compileGroovy
09:32:41.216 [/127.0.0.1:57662 to /127.0.0.1:57661 workers] DEBUG io.micronaut.core.optim.StaticOptimizations - No optimizations class io.micronaut.core.io.service.SoftServiceLoader$Optimizations found
09:32:41.826 [/127.0.0.1:57662 to /127.0.0.1:57661 workers] DEBUG io.micronaut.core.optim.StaticOptimizations - No optimizations class io.micronaut.core.reflect.ClassUtils$Optimizations found
09:32:42.282 [/127.0.0.1:57662 to /127.0.0.1:57661 workers] DEBUG io.micronaut.core.optim.StaticOptimizations - No optimizations class io.micronaut.core.util.EnvironmentProperties found

> Task :compileGsonViews
Execution optimizations have been disabled for task ':compileGsonViews' to ensure correctness due to the following reasons:
  - Gradle detected a problem with the following location: '/Users/shurikag/PRIZ/dev/myapp/build/gson-classes/main'. Reason: Task ':bootWarMainClassName' uses this output of task ':compileGsonViews' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.2/userguide/validation_problems.html#implicit_dependency for more details about this problem.
09:32:44.382 [main] DEBUG io.micronaut.core.optim.StaticOptimizations - No optimizations class io.micronaut.core.reflect.ClassUtils$Optimizations found
09:32:44.388 [main] DEBUG io.micronaut.core.optim.StaticOptimizations - No optimizations class io.micronaut.core.util.EnvironmentProperties found
09:32:45.040 [pool-1-thread-2] DEBUG io.micronaut.core.optim.StaticOptimizations - No optimizations class io.micronaut.core.io.service.SoftServiceLoader$Optimizations found

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.2/userguide/command_line_interface.html#sec:command_line_warnings

Execution optimizations have been disabled for 1 invalid unit(s) of work during this build to ensure correctness.
Please consult deprecation warnings for more details.

更新

如果我将 grailsGradlePluginVersion 更新为 5.1.1 并使用 grails run-app 更新 运行 应用程序,我将面临另一个问题:

| Running application...
<=============> 100% EXECUTING [16s]
> IDLE
Failed to instantiate [ch.qos.logback.classic.LoggerContext]
Reported exception:
ch.qos.logback.core.LogbackException: Unexpected filename extension of file [file:/Users/shurikag/PRIZ/dev/priz-api/grails-app/conf/logback.groovy]. Should be either .groovy or .xml
        at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:67)
        at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:140)
        at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:84)
        at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)
        at org.slf4j.LoggerFactory.bind(LoggerFactory.java:150)
        at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
        at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:417)
        at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:362)
        at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:155)
        at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:290)

我设法让错误消失了。我需要做的就是相关任务的所有依赖配置(在 build.gradle 中):

tasks.named('bootWarMainClassName') {
    it.mustRunAfter(tasks.named('compileGsonViews'))
}

不过,那个sis对表演没有帮助:(

我有同样的错误,升级到 grails 5.1.2 导致错误仍然注销但不再导致它实际失败