import org.gradle.internal.classpath.ClassPath

allprojects { project ->
    task kotlinLSPKotlinDSLDeps {
        // def pattern = ~/^(?:gradle-(?:kotlin-dsl|base-services|plugins|core)|kotlin-(?:compiler|stdlib)).*\.jar/
        def pattern = ~/^.*\.jar/
        doLast {
            (fileTree("$gradle.gradleHomeDir/lib") + fileTree("$gradle.gradleUserHomeDir/caches/$gradle.gradleVersion/generated-gradle-jars") + fileTree("$gradle.gradleUserHomeDir/caches/modules-2/files-2.1"))
                .findAll { it.name =~ pattern }
                .forEach { System.out.println "kotlin-lsp-gradle $it" }

            def projectAccessorsClassPathProperty = "gradleKotlinDsl.projectAccessorsClassPath"
            def pluginAccessorsClassPathProperty = "gradleKotlinDsl.pluginAccessorsClassPath"

            // List dynamically generated Kotlin DSL accessors (e.g. the 'compile' configuration method)
            if (project.hasProperty(projectAccessorsClassPathProperty)) {
                project.getProperty(projectAccessorsClassPathProperty)
                    .bin
                    .asFiles
                    .forEach { System.out.println "kotlin-lsp-gradle $it" }
            }

            if (project.hasProperty(pluginAccessorsClassPathProperty)) {
                project.getProperty(pluginAccessorsClassPathProperty)
                    .bin
                    .asFiles
                    .forEach { System.out.println "kotlin-lsp-gradle $it" }
            }
        }
    }
}
