有没有办法确定 gradle 依赖项(如在 Eclipse IDE 中)在类路径(编译和运行时)中的排序顺序?

Is there a way to determine the order in which gradle dependencies (as in the Eclipse IDE) are ordered in the classpath (compile and runtime)?

我有一个严重的类路径顺序问题,因此我需要确保 JAR 1 在类路径中出现在 JAR 2 之前。

有没有办法在 Eclipse IDE.

的 GRADLE_DEPENDENCIES 中强制执行此操作?

关于在打包应用程序(分发)期间如何实现相同目的的任何见解?

理想情况下,您应该修复项目中的依赖关系,以便在类路径中拥有完全正确的 jar 集。查看 Gradle 文档中 Dependency Management 章节中的如何排除依赖项。

如果您仍想修改 eclipse 的类路径条目,这是一种可能的解决方案。

您可以使用以下方法修改 Gradle 中 eclipse 任务生成的 .classpath 文件:

eclipse.classpath.file {
    withXml {
        // This returns a the classpath XML root node (groovy.util.Node)
        def node = it.asNode()

        // Do the re-rodering of classpath entries by modifying the node object
    }
}

查看 groovy.util.Node 以了解可用于 view/modify XML 节点的方法。

请注意,当您 运行 JVM 中的打包应用程序分发时,您很可能无法控制完成的类路径排序,这将在 运行 时将您拉回到原点当应用程序实际 运行 时。

因此,最好的解决方案是找出类路径中不需要的 jar 依赖项的来源并将其从那里删除,而不是依赖于风险和不可靠的类路径排序。