How to get same list of dependencies in tooling API as in dependencies task?

When I invoke gradle dependencies on a project there is org.jetbrains.kotlin:kotlin-stdlib:2.1.0 in the result, but when I do:

        config.resolve()
        config.incoming.resolutionResult.allDependencies
            .forEach { id ->
                when (id) {
                    is ResolvedDependencyResult -> {
...
                    }
                    is UnresolvedDependencyResult -> {
...
                    }
                }
            }
    }

there is no org.jetbrains.kotlin:kotlin-stdlib:2.1.0 only with versions 1.9.22 and 1.9.24.
What is the right way to get from org.gradle.api.Project the same list of dependencies as in dependencies task?

Probably depends on what your ... look like.
For ResovledDependencyResult for example you have at requested what was requested, i.e. the part left of the -> in dependencies output, for selected what was selected during resolution, i.e. the part right of the -> in dependencies output.

Also you should practically never call resolve() manually.

If you need more targeted help, you probably need to provide an MCVE.