allprojects { project ->
    task kotlinLSPProjectDeps { task ->
        doLast {
            System.out.println ""
            System.out.println "gradle-version $gradleVersion"
            System.out.println "kotlin-lsp-project ${project.name}"

            if (project.hasProperty('android')) {
                project.android.getBootClasspath().each {
                    System.out.println "kotlin-lsp-gradle $it"
                }

                def variants = []

                if (project.android.hasProperty('applicationVariants')) {
                    variants += project.android.applicationVariants
                }

                if (project.android.hasProperty('libraryVariants')) {
                    variants += project.android.libraryVariants
                }

                variants.each { variant ->
                    def variantBase = variant.baseName.replaceAll("-", File.separator)

                    def buildClasses = project.getBuildDir().absolutePath +
                        File.separator + "intermediates" +
                        File.separator + variantBase +
                        File.separator + "classes"

                    System.out.println "kotlin-lsp-gradle $buildClasses"

                    def userClasses = project.getBuildDir().absolutePath +
                        File.separator + "intermediates" +
                        File.separator + "javac" +
                        File.separator + variantBase +
                        File.separator + "compile" + variantBase.capitalize() + "JavaWithJavac" + File.separator + "classes"

                    System.out.println "kotlin-lsp-gradle $userClasses"

                    def userVariantClasses = project.getBuildDir().absolutePath +
                        File.separator + "intermediates" +
                        File.separator + "javac" +
                        File.separator + variantBase +
                        File.separator + "classes"

                    System.out.println "kotlin-lsp-gradle $userVariantClasses"

                    variant.getCompileClasspath().each {
                        System.out.println "kotlin-lsp-gradle $it"
                    }
                }
            } else if (project.hasProperty('sourceSets')) {
                // Print the list of all dependencies jar files.
                sourceSets.forEach {
                    it.compileClasspath.forEach {
                        System.out.println "kotlin-lsp-gradle $it"
                    }
                }
            }


            // handle kotlin multiplatform style dependencies if any
            def kotlinExtension = project.extensions.findByName("kotlin")
            if(kotlinExtension && kotlinExtension.hasProperty("targets")) {
                def kotlinSourceSets = kotlinExtension.sourceSets

                // Print the list of all dependencies jar files.
                kotlinExtension.targets.names.each {
                    def classpath = configurations["${it}CompileClasspath"]
                    classpath.files.each {
                        System.out.println "kotlin-lsp-gradle $it"
                    }
                }
            }
        }
    }

    task kotlinLSPAllGradleDeps {
        doLast {
            fileTree("$gradle.gradleHomeDir/lib")
                .findAll { it.toString().endsWith '.jar' }
                .forEach { System.out.println "kotlin-lsp-gradle $it" }
        }
    }
}
