SonarQube has problems handling Kotlin DSL Gradle build scripts

I have a project that is analyzed with SonarQube 9.9.

As the “Dependency-Check Integration” plugin’s scanner is reporting the findings on the build scripts, I added the build scripts as source files for the analyzed project.

I just ported it from Groovy DSL build scripts to Kotlin DSL build scripts.
If I now run the SonarQube analysis, I get this stacktrace:

Sensor Kotlin Sensor [kotlin]
Could not generate binding context. Proceeding without semantics.
org.jetbrains.kotlin.util.KotlinFrontEndException: Front-end Internal error: Failed to analyze declaration Project_gradle
File being compiled: (1,1) in .../project/project.gradle.kts
The root cause org.jetbrains.kotlin.resolve.lazy.NoDescriptorForDeclarationException was thrown at: org.jetbrains.kotlin.resolve.lazy.BasicAbsentDescriptorHandler.diagnoseDescriptorNotFound(AbsentDescriptorHandler.kt:18)
  at org.jetbrains.kotlin.resolve.ExceptionWrappingKtVisitorVoid.visitDeclaration(ExceptionWrappingKtVisitorVoid.kt:43)
  at org.jetbrains.kotlin.psi.KtVisitorVoid.visitDeclaration(KtVisitorVoid.java:461)
  at org.jetbrains.kotlin.psi.KtVisitorVoid.visitDeclaration(KtVisitorVoid.java:21)
  at org.jetbrains.kotlin.psi.KtVisitor.visitScript(KtVisitor.java:78)
  at org.jetbrains.kotlin.psi.KtVisitorVoid.visitScript(KtVisitorVoid.java:73)
  at org.jetbrains.kotlin.psi.KtVisitorVoid.visitScript(KtVisitorVoid.java:527)
  at org.jetbrains.kotlin.psi.KtVisitorVoid.visitScript(KtVisitorVoid.java:21)
  at org.jetbrains.kotlin.psi.KtScript.accept(KtScript.java:69)
  at org.jetbrains.kotlin.psi.KtElementImplStub.accept(KtElementImplStub.java:49)
  at org.jetbrains.kotlin.resolve.LazyTopDownAnalyzer$analyzeDeclarations$1.registerDeclarations(LazyTopDownAnalyzer.kt:80)
  at org.jetbrains.kotlin.resolve.LazyTopDownAnalyzer$analyzeDeclarations$1.visitKtFile(LazyTopDownAnalyzer.kt:98)
  at org.jetbrains.kotlin.psi.KtVisitorVoid.visitKtFile(KtVisitorVoid.java:521)
  at org.jetbrains.kotlin.psi.KtVisitorVoid.visitKtFile(KtVisitorVoid.java:21)
  at org.jetbrains.kotlin.psi.KtFile.accept(KtFile.kt:249)
  at org.jetbrains.kotlin.psi.KtFile.accept(KtFile.kt:236)
  at org.jetbrains.kotlin.resolve.ExceptionWrappingKtVisitorVoid.visitElement(ExceptionWrappingKtVisitorVoid.kt:27)
  at org.jetbrains.kotlin.com.intellij.psi.PsiElementVisitor.visitFile(PsiElementVisitor.java:35)
  at org.jetbrains.kotlin.psi.KtVisitor.visitKtFile(KtVisitor.java:73)
  at org.jetbrains.kotlin.psi.KtVisitorVoid.visitKtFile(KtVisitorVoid.java:69)
  at org.jetbrains.kotlin.psi.KtVisitorVoid.visitKtFile(KtVisitorVoid.java:521)
  at org.jetbrains.kotlin.psi.KtVisitorVoid.visitKtFile(KtVisitorVoid.java:21)
  at org.jetbrains.kotlin.psi.KtFile.accept(KtFile.kt:249)
  at org.jetbrains.kotlin.psi.KtFile.accept(KtFile.kt:236)
  at org.jetbrains.kotlin.resolve.LazyTopDownAnalyzer.analyzeDeclarations(LazyTopDownAnalyzer.kt:203)
  at org.jetbrains.kotlin.resolve.LazyTopDownAnalyzer.analyzeDeclarations$default(LazyTopDownAnalyzer.kt:58)
  at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:130)
  at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:99)
  at org.sonarsource.kotlin.converter.KotlinCoreEnvironmentToolsKt$analyzeAndGetBindingContext$1.invoke(KotlinCoreEnvironmentTools.kt:113)
  at org.sonarsource.kotlin.converter.KotlinCoreEnvironmentToolsKt$analyzeAndGetBindingContext$1.invoke(KotlinCoreEnvironmentTools.kt:112)
  at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:115)
  at org.sonarsource.kotlin.converter.KotlinCoreEnvironmentToolsKt.analyzeAndGetBindingContext(KotlinCoreEnvironmentTools.kt:112)
  at org.sonarsource.kotlin.converter.KotlinCoreEnvironmentToolsKt.bindingContext(KotlinCoreEnvironmentTools.kt:101)
  at org.sonarsource.kotlin.plugin.KotlinSensor$analyseFiles$bindingContext$1$1.invoke(KotlinSensor.kt:169)
  at org.sonarsource.kotlin.plugin.KotlinSensor$analyseFiles$bindingContext$1$1.invoke(KotlinSensor.kt:168)
  at org.sonarsource.kotlin.plugin.MetricsUtilsKt.measureDuration(MetricsUtils.kt:26)
  at org.sonarsource.kotlin.plugin.KotlinSensor.analyseFiles(KotlinSensor.kt:168)
  at org.sonarsource.kotlin.plugin.KotlinSensor.execute(KotlinSensor.kt:119)
  at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:64)
  at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:88)
  at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:61)
  at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:79)
  at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:61)
  at org.sonar.scanner.scan.SpringModuleScanContainer.doAfterStart(SpringModuleScanContainer.java:82)
  at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
  at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
  at org.sonar.scanner.scan.SpringProjectScanContainer.scan(SpringProjectScanContainer.java:403)
  at org.sonar.scanner.scan.SpringProjectScanContainer.scanRecursively(SpringProjectScanContainer.java:399)
  at org.sonar.scanner.scan.SpringProjectScanContainer.scanRecursively(SpringProjectScanContainer.java:396)
  at org.sonar.scanner.scan.SpringProjectScanContainer.doAfterStart(SpringProjectScanContainer.java:368)
  at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
  at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
  at org.sonar.scanner.bootstrap.SpringGlobalContainer.doAfterStart(SpringGlobalContainer.java:137)
  at org.sonar.core.platform.SpringComponentContainer.startComponents(SpringComponentContainer.java:188)
  at org.sonar.core.platform.SpringComponentContainer.execute(SpringComponentContainer.java:167)
  at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
  at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
  at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.base/java.lang.reflect.Method.invoke(Method.java:566)
  at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
  at com.sun.proxy.$Proxy131.execute(Unknown Source)
  at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
  at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
  at org.sonarqube.gradle.SonarTask.run(SonarTask.java:131)
  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.base/java.lang.reflect.Method.invoke(Method.java:566)
  at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:125)
  at org.gradle.api.internal.project.taskfactory.StandardTaskAction.doExecute(StandardTaskAction.java:58)
  at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:51)
  at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:29)
  at org.gradle.api.internal.tasks.execution.TaskExecution$3.run(TaskExecution.java:236)
  at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:29)
  at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:26)
  at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
  at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
  at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
  at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
  at org.gradle.internal.operations.DefaultBuildOperationRunner.run(DefaultBuildOperationRunner.java:47)
  at org.gradle.internal.operations.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:68)
  at org.gradle.api.internal.tasks.execution.TaskExecution.executeAction(TaskExecution.java:221)
  at org.gradle.api.internal.tasks.execution.TaskExecution.executeActions(TaskExecution.java:204)
  at org.gradle.api.internal.tasks.execution.TaskExecution.executeWithPreviousOutputFiles(TaskExecution.java:187)
  at org.gradle.api.internal.tasks.execution.TaskExecution.execute(TaskExecution.java:165)
  at org.gradle.internal.execution.steps.ExecuteStep.executeInternal(ExecuteStep.java:89)
  at org.gradle.internal.execution.steps.ExecuteStep.access$000(ExecuteStep.java:40)
  at org.gradle.internal.execution.steps.ExecuteStep$1.call(ExecuteStep.java:53)
  at org.gradle.internal.execution.steps.ExecuteStep$1.call(ExecuteStep.java:50)
  at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
  at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:199)
  at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
  at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
  at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
  at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
  at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
  at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:73)
  at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:50)
  at org.gradle.internal.execution.steps.ExecuteStep.execute(ExecuteStep.java:40)
  at org.gradle.internal.execution.steps.RemovePreviousOutputsStep.execute(RemovePreviousOutputsStep.java:68)
  at org.gradle.internal.execution.steps.RemovePreviousOutputsStep.execute(RemovePreviousOutputsStep.java:38)
  at org.gradle.internal.execution.steps.CancelExecutionStep.execute(CancelExecutionStep.java:41)
  at org.gradle.internal.execution.steps.TimeoutStep.executeWithoutTimeout(TimeoutStep.java:74)
  at org.gradle.internal.execution.steps.TimeoutStep.execute(TimeoutStep.java:55)
  at org.gradle.internal.execution.steps.CreateOutputsStep.execute(CreateOutputsStep.java:51)
  at org.gradle.internal.execution.steps.CreateOutputsStep.execute(CreateOutputsStep.java:29)
  at org.gradle.internal.execution.steps.CaptureStateAfterExecutionStep.executeDelegateBroadcastingChanges(CaptureStateAfterExecutionStep.java:124)
  at org.gradle.internal.execution.steps.CaptureStateAfterExecutionStep.execute(CaptureStateAfterExecutionStep.java:80)
  at org.gradle.internal.execution.steps.CaptureStateAfterExecutionStep.execute(CaptureStateAfterExecutionStep.java:58)
  at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:48)
  at org.gradle.internal.execution.steps.ResolveInputChangesStep.execute(ResolveInputChangesStep.java:36)
  at org.gradle.internal.execution.steps.BuildCacheStep.executeWithoutCache(BuildCacheStep.java:181)
  at org.gradle.internal.execution.steps.BuildCacheStep.lambda$execute$1(BuildCacheStep.java:71)
  at org.gradle.internal.Either$Right.fold(Either.java:175)
  at org.gradle.internal.execution.caching.CachingState.fold(CachingState.java:59)
  at org.gradle.internal.execution.steps.BuildCacheStep.execute(BuildCacheStep.java:69)
  at org.gradle.internal.execution.steps.BuildCacheStep.execute(BuildCacheStep.java:47)
  at org.gradle.internal.execution.steps.StoreExecutionStateStep.execute(StoreExecutionStateStep.java:36)
  at org.gradle.internal.execution.steps.StoreExecutionStateStep.execute(StoreExecutionStateStep.java:25)
  at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:36)
  at org.gradle.internal.execution.steps.RecordOutputsStep.execute(RecordOutputsStep.java:22)
  at org.gradle.internal.execution.steps.SkipUpToDateStep.executeBecause(SkipUpToDateStep.java:110)
  at org.gradle.internal.execution.steps.SkipUpToDateStep.lambda$execute$2(SkipUpToDateStep.java:56)
  at java.base/java.util.Optional.orElseGet(Optional.java:369)
  at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:56)
  at org.gradle.internal.execution.steps.SkipUpToDateStep.execute(SkipUpToDateStep.java:38)
  at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:73)
  at org.gradle.internal.execution.steps.ResolveChangesStep.execute(ResolveChangesStep.java:44)
  at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:37)
  at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsFinishedStep.execute(MarkSnapshottingInputsFinishedStep.java:27)
  at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:89)
  at org.gradle.internal.execution.steps.ResolveCachingStateStep.execute(ResolveCachingStateStep.java:50)
  at org.gradle.internal.execution.steps.ValidateStep.execute(ValidateStep.java:102)
  at org.gradle.internal.execution.steps.ValidateStep.execute(ValidateStep.java:57)
  at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.execute(CaptureStateBeforeExecutionStep.java:76)
  at org.gradle.internal.execution.steps.CaptureStateBeforeExecutionStep.execute(CaptureStateBeforeExecutionStep.java:50)
  at org.gradle.internal.execution.steps.SkipEmptyWorkStep.executeWithNoEmptySources(SkipEmptyWorkStep.java:254)
  at org.gradle.internal.execution.steps.SkipEmptyWorkStep.execute(SkipEmptyWorkStep.java:91)
  at org.gradle.internal.execution.steps.SkipEmptyWorkStep.execute(SkipEmptyWorkStep.java:56)
  at org.gradle.internal.execution.steps.RemoveUntrackedExecutionStateStep.execute(RemoveUntrackedExecutionStateStep.java:32)
  at org.gradle.internal.execution.steps.RemoveUntrackedExecutionStateStep.execute(RemoveUntrackedExecutionStateStep.java:21)
  at org.gradle.internal.execution.steps.legacy.MarkSnapshottingInputsStartedStep.execute(MarkSnapshottingInputsStartedStep.java:38)
  at org.gradle.internal.execution.steps.LoadPreviousExecutionStateStep.execute(LoadPreviousExecutionStateStep.java:43)
  at org.gradle.internal.execution.steps.LoadPreviousExecutionStateStep.execute(LoadPreviousExecutionStateStep.java:31)
  at org.gradle.internal.execution.steps.AssignWorkspaceStep.lambda$execute$0(AssignWorkspaceStep.java:40)
  at org.gradle.api.internal.tasks.execution.TaskExecution$4.withWorkspace(TaskExecution.java:281)
  at org.gradle.internal.execution.steps.AssignWorkspaceStep.execute(AssignWorkspaceStep.java:40)
  at org.gradle.internal.execution.steps.AssignWorkspaceStep.execute(AssignWorkspaceStep.java:30)
  at org.gradle.internal.execution.steps.IdentityCacheStep.execute(IdentityCacheStep.java:37)
  at org.gradle.internal.execution.steps.IdentityCacheStep.execute(IdentityCacheStep.java:27)
  at org.gradle.internal.execution.steps.IdentifyStep.execute(IdentifyStep.java:44)
  at org.gradle.internal.execution.steps.IdentifyStep.execute(IdentifyStep.java:33)
  at org.gradle.internal.execution.impl.DefaultExecutionEngine$1.execute(DefaultExecutionEngine.java:76)
  at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:139)
  at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:128)
  at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:77)
  at org.gradle.api.internal.tasks.execution.FinalizePropertiesTaskExecuter.execute(FinalizePropertiesTaskExecuter.java:46)
  at org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter.execute(ResolveTaskExecutionModeExecuter.java:51)
  at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:57)
  at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:57)
  at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:36)
  at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.executeTask(EventFiringTaskExecuter.java:77)
  at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:55)
  at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter$1.call(EventFiringTaskExecuter.java:52)
  at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
  at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:199)
  at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
  at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
  at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
  at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
  at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
  at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:73)
  at org.gradle.api.internal.tasks.execution.EventFiringTaskExecuter.execute(EventFiringTaskExecuter.java:52)
  at org.gradle.execution.plan.LocalTaskNodeExecutor.execute(LocalTaskNodeExecutor.java:69)
  at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:322)
  at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$InvokeNodeExecutorsAction.execute(DefaultTaskExecutionGraph.java:309)
  at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:302)
  at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph$BuildOperationAwareExecutionAction.execute(DefaultTaskExecutionGraph.java:288)
  at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.execute(DefaultPlanExecutor.java:462)
  at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:379)
  at org.gradle.execution.plan.DefaultPlanExecutor.process(DefaultPlanExecutor.java:115)
  at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph.executeWithServices(DefaultTaskExecutionGraph.java:135)
  at org.gradle.execution.taskgraph.DefaultTaskExecutionGraph.execute(DefaultTaskExecutionGraph.java:120)
  at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:35)
  at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:51)
  at org.gradle.execution.BuildOperationFiringBuildWorkerExecutor$ExecuteTasks.call(BuildOperationFiringBuildWorkerExecutor.java:54)
  at org.gradle.execution.BuildOperationFiringBuildWorkerExecutor$ExecuteTasks.call(BuildOperationFiringBuildWorkerExecutor.java:43)
  at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
  at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:199)
  at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
  at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
  at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
  at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
  at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
  at org.gradle.internal.operations.DefaultBuildOperationExecutor.call(DefaultBuildOperationExecutor.java:73)
  at org.gradle.execution.BuildOperationFiringBuildWorkerExecutor.execute(BuildOperationFiringBuildWorkerExecutor.java:40)
  at org.gradle.internal.build.DefaultBuildLifecycleController.lambda$executeTasks$6(DefaultBuildLifecycleController.java:167)
  at org.gradle.internal.model.StateTransitionController.doTransition(StateTransitionController.java:247)
  at org.gradle.internal.model.StateTransitionController.lambda$tryTransition$7(StateTransitionController.java:174)
  at org.gradle.internal.work.DefaultSynchronizer.withLock(DefaultSynchronizer.java:44)
  at org.gradle.internal.model.StateTransitionController.tryTransition(StateTransitionController.java:174)
  at org.gradle.internal.build.DefaultBuildLifecycleController.executeTasks(DefaultBuildLifecycleController.java:167)
  at org.gradle.internal.build.DefaultBuildWorkGraphController$DefaultBuildWorkGraph.runWork(DefaultBuildWorkGraphController.java:190)
  at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:249)
  at org.gradle.internal.work.DefaultWorkerLeaseService.runAsWorkerThread(DefaultWorkerLeaseService.java:109)
  at org.gradle.composite.internal.DefaultBuildController.doRun(DefaultBuildController.java:172)
  at org.gradle.composite.internal.DefaultBuildController.access$000(DefaultBuildController.java:47)
  at org.gradle.composite.internal.DefaultBuildController$BuildOpRunnable.run(DefaultBuildController.java:191)
  at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
  at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
  at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
  at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:49)
  at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
  at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
  at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: org.jetbrains.kotlin.resolve.lazy.NoDescriptorForDeclarationException: Descriptor wasn't found for declaration SCRIPT
  at org.jetbrains.kotlin.resolve.lazy.BasicAbsentDescriptorHandler.diagnoseDescriptorNotFound(AbsentDescriptorHandler.kt:18)
  at org.jetbrains.kotlin.resolve.lazy.BasicAbsentDescriptorHandler.diagnoseDescriptorNotFound(AbsentDescriptorHandler.kt:17)
  at org.jetbrains.kotlin.resolve.lazy.LazyDeclarationResolver.findClassDescriptor(LazyDeclarationResolver.kt:88)
  at org.jetbrains.kotlin.resolve.lazy.LazyDeclarationResolver.getScriptDescriptor(LazyDeclarationResolver.kt:65)
  at org.jetbrains.kotlin.resolve.LazyTopDownAnalyzer$analyzeDeclarations$1.visitScript(LazyTopDownAnalyzer.kt:91)
  at org.jetbrains.kotlin.psi.KtVisitorVoid.visitScript(KtVisitorVoid.java:527)
  at org.jetbrains.kotlin.psi.KtVisitorVoid.visitScript(KtVisitorVoid.java:21)
  at org.jetbrains.kotlin.psi.KtScript.accept(KtScript.java:69)
  at org.jetbrains.kotlin.psi.KtElementImplStub.accept(KtElementImplStub.java:49)
  at org.jetbrains.kotlin.resolve.ExceptionWrappingKtVisitorVoid.visitDeclaration(ExceptionWrappingKtVisitorVoid.kt:32)
  ... 216 common frames omitted

Hey there.

Can you share this file? It will be hard to debug a failure without it.

I don’t think it will be hard to reproduce, as I think it just happens with all Kotlin DSL Gradle build scripts that you add to the sources.

As almost all the logic is in convention plugins, those build scripts are almost empty.
One for example only has:

plugins {
    `java-library`
    com.example.sonarqube
}

dependencies {
    compileOnly(libs.jackson.databind)
    compileOnly(libs.jackson.annotations)
    api(libs.jackson.core)
}

Hm, seems I maybe was wrong.
Indeed 1 of the 5 build scripts is not complained about, although it is way more complex than that.
But the one difference I see that the failing have in common and the other one has not,
is the usage of version catalog accessors.
The build script it did not complain about does not even have a dependenices { ... } block.

Just to avoid confusion.
I meant I was wrong with saying that it happens on all Kotlin DSL Gradle files.
The issue nevertheless is there.

The issue here occurs because we’re trying to build a semantic model for a Grade script. This feature is not ready yet; we only analyze the syntax of the Gradle build scripts.

However, it looks like we overlooked when the Gradle script isn’t named build. This way, the analyzer assumes it’s an ordinary Koltin script and tries to build a semantic model.

The workaround will be to ignore these files for now, so you can add them to exclusions. And I’ve created a ticket to fix it:

https://sonarsource.atlassian.net/browse/SONARKT-402

In the future I hope we’ll be able to analyze Gradle scripts with Semanctic and have more valuable rules for them.

Best,
Margarita

Thanks for your answer, but what exactly do you mean be “add them to exclusions”?
I explicitly add them to sources because the dependency check plugin reports on them its findings.
Or did you mean just to exclude them from the built-in Kotlin analysis?
Can you quickly tell me with which property I would do that?

And why does it not complain for the 5th build script?
It also does not have the name build.gradle.kts but a custom one.

(Having multiple files called build.gradle.kts in one project is always a pain for navigation and especially when debugging build scripts as you then often land in the wrong one as the stack frames do not include the path of the build script)

(Besides that there can also be precompiled script plugins with similar names where it even is more common or actually almost mandatory to have different names)

Hi Bjorn,

Sorry, it took me more time to get back to you than I expected.

I completely missed the fact that you’re on 9.9. That version of analyzer wasn’t designed to analyze Gradle build scripts and Kotlin scripts in general. So, the built-in analyzer, by default, only runs on .kt files. However, if you change the extensions to allow .kts, the analysis will run on them (even if it’s not supposed to).

In 10.X, we added the capability to analyze Gradle scripts and fixed the issue, so the default sensor shouldn’t run on anything with a .kts extension.

As I understood, you’re using this community plugin for SQ (GitHub - dependency-check/dependency-check-sonar-plugin: Integrates Dependency-Check reports into SonarQube), which we don’t control and thus can’t predict potential issues.

Why the issue doesn’t appear in all build scripts depends on the content of the build script. It could happen that the Kotlin compiler didn’t understand that it was a script and was able to compile it as a Kotlin file (anyway, that’s just an assumption).

So the good news, if you move to the newer versions of SQ, your issue must be resolved. As for mitigation for now:

  • you can migrate to the newer SQ versions
  • you can postpone the migration to Kotlin DSL if you want to still benefit from the dependencies check.
  • you can remove .kts from Kotlin language extensions, but you will lose dependencies check

Meanwhile, I will try to think of what we can do from our side and if there’s an easy workaround so that you can disable the built-in analyzer’s analysis of Kotlin build scripts but still benefit from other sensors.

Best,
Margarita

Actually, that exception in the logs does not make the analysis fail.So for now I can probably also live with how it is right now, thanks.
I can also try removing the .kts extension, I have no idea why it was added. I’d expect the dependency check to also work without it.