DEV Community

Query Filter
Query Filter

Posted on

dupl4

task checkCacheDuplicates {
    doLast {
        // 1. Get all files from the compile classpath (including the Gradle cache)
        def allJars = configurations.compileClasspath.files

        // 2. Filter for the two specific JARs you mentioned
        def jar1 = allJars.find { it.name.contains("EQRioINtf") }
        def jar2 = allJars.find { it.name.contains("OESIntf") }

        if (jar1 && jar2) {
            println "--- Comparing JARs found in Cache ---"
            println "JAR 1: ${jar1.absolutePath}"
            println "JAR 2: ${jar2.absolutePath}"

            def classMap = [:]
            [jar1, jar2].each { file ->
                def zip = new java.util.zip.ZipFile(file)
                zip.entries().each { entry ->
                    if (entry.name.endsWith('.class')) {
                        if (classMap.containsKey(entry.name)) {
                            println "DUPLICATE: ${entry.name}"
                        } else {
                            classMap[entry.name] = file.name
                        }
                    }
                }
                zip.close()
            }
        } else {
            println "Could not find both JARs in the current compileClasspath."
            println "Found JAR 1: ${jar1?.name ?: 'MISSING'}"
            println "Found JAR 2: ${jar2?.name ?: 'MISSING'}"
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)