Strumenta / antlr-kotlin

Support for Kotlin as a target for ANTLR 4
Apache License 2.0
221 stars 47 forks source link

Fail on execute AntlrKotlinTask with Gradle 8.7 #177

Closed Komdosh closed 4 months ago

Komdosh commented 4 months ago

I tried to run the Gradle task AntlrKotlinTask, but it failed.

I'm using gradle 8.7 with kotlin dsl and Java 21. I have applied plugin and add dependency. Kotlin multiplatform (JVM + JS).

Configuration cache - turn on. When cache turn off - task is always "UP-TO-DATE"

val generateGrammarSource by
tasks.registering(AntlrKotlinTask::class) {
//    maxHeapSize = "64m"
    arguments = arguments + listOf("-Dlanguage=Kotlin", "-visitor")
    source =
        project.objects
            .sourceDirectorySet("antlr", "antlr")
            .srcDir("src/commonAntlr/antlr")
            .apply { include("*.g4") }

    val pkgName = "com.strumenta.antlrkotlin.parsers.generated"
    packageName = pkgName

    // outputDirectory is required, put it into the build directory
    // if you do not want to add the generated sources to version control
    outputDirectory = File("build/generated-src/commonAntlr/kotlin")
}

Gradle Error:

FAILURE: Build failed with an exception.

* What went wrong:
Configuration cache state could not be cached: field `logger` of `org.gradle.internal.logging.source.JavaUtilLoggingSystem` bean found in field `loggingSystem` of `org.gradle.internal.logging.services.DefaultLoggingManager$StartableLoggingSystem` bean found in field `javaUtilLoggingSystem` of `org.gradle.internal.logging.services.DefaultLoggingManager` bean found in field `loggingManager` of `org.gradle.process.internal.worker.DefaultWorkerProcessFactory` bean found in field `workerProcessBuilderFactory` of task `:common:expression:generateGrammarSource` of type `com.strumenta.antlrkotlin.gradle.AntlrKotlinTask`: error writing value of type 'java.util.logging.LogManager$RootLogger'
> Unable to make field final java.util.logging.LogManager java.util.logging.LogManager$RootLogger.this$0 accessible: module java.logging does not "opens java.util.logging" to unnamed module @67c339bb

I've tried to open all necessary java modules.

--add-opens=java.logging/java.util.logging=ALL-UNNAMED --add-opens java.locks/java.util.concurrent.locks=ALL-UNNAMED --add-opens java.base/java.util.concurrent.locks=ALL-UNNAMED --add-opens java.base/java.lang.ref=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED --add-opens java.base/sun.util.calendar=ALL-UNNAMED --add-opens java.base/java.util.concurrent=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED

There is another error:

Could not load the value of field `m` of `java.util.Collections$SynchronizedMap` bean found in field `listeners` of `java.util.logging.LogManager` bean found in field `this$0` of `java.util.logging.LogManager$RootLogger` bean found in field `logger` of `org.gradle.internal.logging.source.JavaUtilLoggingSystem` bean found in field `loggingSystem` of `org.gradle.internal.logging.services.DefaultLoggingManager$StartableLoggingSystem` bean found in field `javaUtilLoggingSystem` of `org.gradle.internal.logging.services.DefaultLoggingManager` bean found in field `loggingManager` of `org.gradle.process.internal.worker.DefaultWorkerProcessFactory` bean found in field `workerProcessBuilderFactory` of task `:common:expression:generateGrammarSource` of type `com.strumenta.antlrkotlin.gradle.AntlrKotlinTask`.

Gradle: configuration cache report in attachment (Github not allow to attach html, so please, change file type to html to view report). If you need any details, please let me know.

configuration-cache-report.log

ftomassetti commented 4 months ago

Thank you for reporting! For the time being, can you use a previous version of Gradle? Does that solve your issue?

Komdosh commented 4 months ago

I tried using Gradle 7.6, and it started working only after I disabled the configuration cache (there was a different property name for it in Gradle 8.7, so I forgot to update it after downgrading).

Disabling the configuration cache actually resolved the issue. It seems notCompatibleWithConfigurationCache wasn't working as expected with org.gradle.configuration-cache.problems=warn in Gradle (or possibly earlier versions).

In Gradle 8.7, disabling configuration cache in task and setting org.gradle.configuration-cache.problems=disabled in gradle.properties resolves the issue.

val generateGrammarSource by
tasks.registering(AntlrKotlinTask::class) {
    notCompatibleWithConfigurationCache("generateGrammarSource not compatible with ConfigurationCache")
 ....
 }}

So the problem is in configuration cache.

P.S. Warnings are still here but it builds anyway

35 problems were found storing the configuration cache, 11 of which seem unique.
- Task `:common:expression:generateGrammarSource` of type `com.strumenta.antlrkotlin.gradle.AntlrKotlinTask`: cannot serialize object of type 'java.io.PrintStream', a subtype of 'java.io.OutputStream', as these are not supported with the configuration cache. Only 'System.out' or 'System.err' can be used there.
  See https://docs.gradle.org/8.7/userguide/configuration_cache.html#config_cache:requirements:disallowed_types
- Task `:common:expression:generateGrammarSource` of type `com.strumenta.antlrkotlin.gradle.AntlrKotlinTask`: cannot serialize object of type 'jdk.internal.loader.ClassLoaders$AppClassLoader', a subtype of 'java.lang.ClassLoader', as these are not supported with the configuration cache.
  See https://docs.gradle.org/8.7/userguide/configuration_cache.html#config_cache:requirements:disallowed_types
- Task `:common:expression:generateGrammarSource` of type `com.strumenta.antlrkotlin.gradle.AntlrKotlinTask`: cannot serialize object of type 'org.gradle.internal.concurrent.DefaultExecutorFactory$TrackedScheduledManagedExecutor', a subtype of 'java.util.concurrent.Executor', as these are not supported with the configuration cache.
  See https://docs.gradle.org/8.7/userguide/configuration_cache.html#config_cache:requirements:disallowed_types
- Task `:common:expression:generateGrammarSource` of type `com.strumenta.antlrkotlin.gradle.AntlrKotlinTask`: cannot serialize object of type 'org.gradle.internal.event.DefaultListenerManager$EventBroadcast$ListenerDispatch', a subtype of 'org.gradle.internal.event.AbstractBroadcastDispatch', as these are not supported with the configuration cache.
  See https://docs.gradle.org/8.7/userguide/configuration_cache.html#config_cache:requirements:disallowed_types
- Task `:common:expression:generateGrammarSource` of type `com.strumenta.antlrkotlin.gradle.AntlrKotlinTask`: cannot serialize object of type 'org.gradle.internal.event.ListenerBroadcast', a subtype of 'org.gradle.internal.event.ListenerBroadcast', as these are not supported with the configuration cache.
  See https://docs.gradle.org/8.7/userguide/configuration_cache.html#config_cache:requirements:disallowed_types
- Task `:common:expression:generateGrammarSource` of type `com.strumenta.antlrkotlin.gradle.AntlrKotlinTask`: error writing value of type '[Ljava.util.WeakHashMap$Entry;'
- Task `:common:expression:generateGrammarSource` of type `com.strumenta.antlrkotlin.gradle.AntlrKotlinTask`: error writing value of type 'java.lang.ref.ReferenceQueue'
- Task `:common:expression:generateGrammarSource` of type `com.strumenta.antlrkotlin.gradle.AntlrKotlinTask`: error writing value of type 'java.text.SimpleDateFormat'
- Task `:common:expression:generateGrammarSource` of type `com.strumenta.antlrkotlin.gradle.AntlrKotlinTask`: error writing value of type 'java.util.concurrent.ConcurrentSkipListMap'
- Task `:common:expression:generateGrammarSource` of type `com.strumenta.antlrkotlin.gradle.AntlrKotlinTask`: error writing value of type 'java.util.concurrent.locks.ReentrantLock'
- Task `:common:expression:generateGrammarSource` of type `com.strumenta.antlrkotlin.gradle.AntlrKotlinTask`: error writing value of type 'java.util.logging.LogManager$RootLogger'
lppedd commented 4 months ago

AntlrKotlinTask is marked as cachable, but down the line we're using something that hasn't been thought to be cache-compatible. I think that's the gist of it.

I'll have a look if we can do something about it on our side.

lppedd commented 4 months ago

I can't even get to a point where I can repro.

30 problems were found storing the configuration cache, 12 of which seem unique.
- Task `:faproto:compileProductionLibraryKotlinJs` of type `org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLink`: cannot serialize object of type 'org.gradle.api.internal.artifacts.configurations.DefaultConfigurationContainer', a subtype of 'org.gradle.api.artifacts.ConfigurationContainer', as these are not supported with the configuration cache.
  See https://docs.gradle.org/8.7/userguide/configuration_cache.html#config_cache:requirements:disallowed_types
- Task `:faproto:compileProductionLibraryKotlinJs` of type `org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLink`: cannot serialize object of type 'org.gradle.api.internal.artifacts.configurations.DefaultUnlockedConfiguration', a subtype of 'org.gradle.api.artifacts.Configuration', as these are not supported with the configuration cache.
  See https://docs.gradle.org/8.7/userguide/configuration_cache.html#config_cache:requirements:disallowed_types
- Task `:faproto:compileProductionLibraryKotlinJs` of type `org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLink`: cannot serialize object of type 'org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler', a subtype of 'org.gradle.api.artifacts.dsl.DependencyHandler', as these are not supported with the configuration cache.
  See https://docs.gradle.org/8.7/userguide/configuration_cache.html#config_cache:requirements:disallowed_types
- Task `:faproto:compileProductionLibraryKotlinJs` of type `org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLink`: cannot serialize object of type 'org.gradle.api.internal.file.DefaultSourceDirectorySet', a subtype of 'org.gradle.api.file.SourceDirectorySet', as these are not supported with the configuration cache.
  See https://docs.gradle.org/8.7/userguide/configuration_cache.html#config_cache:requirements:disallowed_types
- Task `:faproto:compileProductionLibraryKotlinJs` of type `org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLink`: cannot serialize object of type 'org.gradle.api.internal.project.DefaultProject', a subtype of 'org.gradle.api.Project', as these are not supported with the configuration cache.
  See https://docs.gradle.org/8.7/userguide/configuration_cache.html#config_cache:requirements:disallowed_types
- Task `:faproto:compileProductionLibraryKotlinJs` of type `org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLink`: cannot serialize object of type 'org.jetbrains.kotlin.gradle.targets.js.npm.PublicPackageJsonTask', a subtype of 'org.gradle.api.Task', as these are not supported with the configuration cache.
  See https://docs.gradle.org/8.7/userguide/configuration_cache.html#config_cache:requirements:task_access
- Task `:faproto:compileProductionLibraryKotlinJs` of type `org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLink`: cannot serialize object of type 'org.jetbrains.kotlin.gradle.targets.js.npm.tasks.KotlinPackageJsonTask', a subtype of 'org.gradle.api.Task', as these are not supported with the configuration cache.
  See https://docs.gradle.org/8.7/userguide/configuration_cache.html#config_cache:requirements:task_access
- Task `:faproto:compileProductionLibraryKotlinJs` of type `org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLink`: cannot serialize object of type 'org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockCopyTask', a subtype of 'org.gradle.api.Task', as these are not supported with the configuration cache.
  See https://docs.gradle.org/8.7/userguide/configuration_cache.html#config_cache:requirements:task_access
- Task `:faproto:compileProductionLibraryKotlinJs` of type `org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLink`: cannot serialize object of type 'org.jetbrains.kotlin.gradle.targets.js.yarn.YarnLockStoreTask', a subtype of 'org.gradle.api.Task', as these are not supported with the configuration cache.
  See https://docs.gradle.org/8.7/userguide/configuration_cache.html#config_cache:requirements:task_access
- Task `:faproto:compileProductionLibraryKotlinJs` of type `org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLink`: cannot serialize object of type 'org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmRun', a subtype of 'org.gradle.api.Task', as these are not supported with the configuration cache.
  See https://docs.gradle.org/8.7/userguide/configuration_cache.html#config_cache:requirements:task_access
- Task `:faproto:compileProductionLibraryKotlinJs` of type `org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLink`: cannot serialize object of type 'org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest', a subtype of 'org.gradle.api.Task', as these are not supported with the configuration cache.
  See https://docs.gradle.org/8.7/userguide/configuration_cache.html#config_cache:requirements:task_access
- Task `:faproto:compileProductionLibraryKotlinJs` of type `org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrLink`: cannot serialize object of type 'org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile', a subtype of 'org.gradle.api.Task', as these are not supported with the configuration cache.
  See https://docs.gradle.org/8.7/userguide/configuration_cache.html#config_cache:requirements:task_access
Komdosh commented 4 months ago

@lppedd

I can't even get to a point where I can repro.

Check this example:

https://github.com/Komdosh/ANTLR4131CachingProblem

lppedd commented 4 months ago

Thanks! Fixed. Will open a PR soon.