简体   繁体   English

IntelliJ 混淆了 Gradle 依赖与不同的项目 - 仍然有效

[英]IntelliJ confuses Gradle dependency with different project - still works

The situation: I have two separate Gradle projects imported in IntelliJ idea.情况:我在 IntelliJ IDEA 中导入了两个单独的 Gradle 项目。 Both projects use a framework called Mason.这两个项目都使用一个名为 Mason 的框架。 Project A was imported first and has no issues, it uses the newer Version of Mason, which is stored locally in a folder, called 'lib', as Mason.20.jar (none of the Mason versions used here are on Maven Central).项目 A 首先导入并且没有问题,它使用较新版本的 Mason,它存储在本地名为“lib”的文件夹中,如 Mason.20.jar(此处使用的 Mason 版本均不在 Maven Central)。 Project B was imported later and uses an older Version, which is stored in a folder, also called 'lib', as Mason.19.jar (some elements are not compatible with Mason.20).项目 B 是后来导入的,使用旧版本,存储在文件夹中,也称为“lib”,如 Mason.19.jar(某些元素与 Mason.20 不兼容)。 Both projects are structured the same way and both have the library folder as "Root/lib/", however otherwise the two projects are fully independent from each other and don't even reference each other.这两个项目的结构相同,并且都将库文件夹设置为“Root/lib/”,但除此之外,这两个项目完全相互独立,甚至不相互引用。

The actual issue: IntelliJ now has issues evaluating Project B, because it looks for the "Mason.20.jar" in "ProjectB/lib/Mason.20.jar", even though it's not referenced anywhere in Project B's build.gradle file.实际问题:IntelliJ 现在在评估项目 B 时遇到问题,因为它在“ProjectB/lib/Mason.20.jar”中查找“Mason.20.jar”,即使项目 B 的 build.gradle 文件中的任何地方都没有引用它。 And the project itself is also totally fine, I can run the Gradle tasks without any issue, in and outside of IntelliJ.而且项目本身也完全没问题,我可以在 IntelliJ 内外毫无问题地运行 Gradle 任务。 This issue also only came up after I recently setup my Laptop.这个问题也是在我最近设置笔记本电脑后才出现的。

I tried the Gradle sync button from IntelliJ and checked if the dependencies where messed up, but couldn't find anything.我尝试了 IntelliJ 的 Gradle 同步按钮并检查依赖项是否搞砸了,但找不到任何东西。 I'm guessing that IntelliJ just mixes up the caches from the two Projects, but I have no idea how to fix that.我猜 IntelliJ 只是混淆了两个项目的缓存,但我不知道如何解决这个问题。

This is the Gradle task I use to generate the jar file for Project B and also where the error supposedly lies:这是我用来为项目 B 生成 jar 文件的 Gradle 任务,也是错误所在:

task distribute(type: Jar){
    from sourceSets.main.output
    from (configurations.compile.collect {zipTree(it)}){ <--this is where IntelliJ complains
        exclude 'META-INF/MANIFEST.MF'
        exclude 'META-INF/*.SF'
        exclude 'META-INF/*.DSA'
        exclude 'META-INF/*.RSA'
    }

    manifest {
        attributes 'Main-Class': project.mainClassName
    }

    doLast{
        copy {
            from "/build/libs/"
            from "./logging.properties"
            into "./jar"
        }
        copy {
            from "./parameters"
            into "./jar/parameters"
        }
        copy{
            from "./README.txt"
            into "./jar"
            }

        copy{
            from "./batch/"
            into "./jar/batch"
        }

        file(new File(projectDir, "/build")).deleteDir()
        file(new File(projectDir, "/jar/batch/linux/buildJar")).delete()
        file(new File(projectDir, "/jar/batch/windows/buildJar.bat")).delete()
    }
}

And for comparison the equivalent Gradle task for Project A:为了比较,项目 A 的等效 Gradle 任务:

task distribute(type: Jar){
outputs.upToDateWhen { false }
    from sourceSets.main.output
    from (configurations.compile.collect {zipTree(it)}){
        exclude 'META-INF/MANIFEST.MF'
        exclude 'META-INF/*.SF'
        exclude 'META-INF/*.DSA'
        exclude 'META-INF/*.RSA'
    }

    manifest {
        attributes 'Main-Class': project.mainClassName
    }

    doLast {
        copy {
            from "/build/libs/"
            into "./jar"
        }
        copy {
            from "./Config"
            into "./jar/Config"
        }
        copy{
            from "./README.txt"
            into "./jar"
            }
        copy {
            from "./scriptfiles"
            into "./jar/scriptfiles"
        }

        file(new File(projectDir, "/build")).deleteDir()
    }
}

Any ideas how to fix this?任何想法如何解决这一问题?

After a bit of trying around I found a Solution more or less.经过一番尝试后,我或多或少找到了解决方案。 It seems IntelliJ might not have been the issue, but Gradle itself.看来 IntelliJ 可能不是问题所在,而是 Gradle 本身。 After I manually deleted the Gradle cache located under: %USERPROFILE%\.gradle\caches the issue was gone and even after I switched back to Project A in IntelliJ (did not re-import it and also did not yet build it) it still worked fine.在我手动删除位于%USERPROFILE%\.gradle\caches下的 Gradle 缓存之后,问题就消失了,甚至在我切换回 IntelliJ 中的项目 A 之后(没有重新导入它,也没有构建它)它仍然工作正常。 However I don't know how it would behave if I re-import a Project.但是我不知道如果我重新导入一个项目它会如何表现。 One thing to Note is that Project A uses a newer Version of the Library in Question, so it might be more reliable to import the project with an older Library first.需要注意的一件事是项目 A 使用了问题库的较新版本,因此首先使用较旧的库导入项目可能更可靠。 It might also have been just a random one-time bug.它也可能只是一个随机的一次性错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM