在 Gradle 中实现 IntelliJ“选择源”对话框的结果 核心问题尝试Eclipse 的 Gradle 代码

问题描述

上下文

我正在为具有相当复杂的 Gradle 文件系统的 Java 项目 (Ghidra) 构建扩展。 IntelliJ 正确地获取依赖项 jar,但每次打开 .class 文件时(例如在调试期间)IntelliJ 都会在顶部显示一个横幅,说明: Decompiled .class file,bytecode version: 55.0 (Java 11) Choose Sources...

Choose Sources 打开对话框选择源,可以选择 *-src.zip 文件旁边的 *.jar 添加源。这也可以通过项目设置来完成。 在后一种情况下有一个明确的警告:A Library is imported from Gradle. Any changes made in its configuration might be lost after reimporting.。使用 Choose Sources 时仍会出现这种情况,只是没有警告。

核心问题

如何以 IntelliJ(或任何其他 IDE)自动识别的方式将源添加到 Gradle 配置? IE。实现 IntelliJ IDEA 中的 Choose Sources 对话框功能的 Gradle 指令是什么?

在 Gradle 文件中声明依赖项的方式,即包含在实际的 build.gradle 中,如下所示:

dependencies {
    api filetree(dir: ghidraDir + '/Framework',include: "**/*.jar")
}

尝试

我的第一次尝试是将其更改为 api filetree(dir: ghidraDir + '/Framework',includes: ["**/*.jar","**/*-src.zip"]),但这会将 zip 作为单独的存档文件添加到 IntelliJ 中,而不是作为依赖项 jar 的源。

Eclipse 的 Gradle 代码

似乎对 Eclipse 实现相同结果的 Gradle 代码如下所示,特别是 entry.setSourcePath

eclipse {
    classpath {
        downloadJavadoc = true
        downloadSources = true
        file {
            whenMerged {
                File javaDoc = new File(ghidraInstallDir+"/docs/GhidraAPI_javadoc.zip");
                for (entry in entries) {
                    if (entry.path.contains('jar')) {
                        File folder = new File(entry.getPath()).getParentFile();
                        for (File file : folder.listFiles()) {
                            if (file.getName().endsWith(".zip")) {
                                if (file.getName().contains("-src")) {
                                    entry.setSourcePath(it.fileReference(file));
                                }
                                entry.setJavadocPath(it.fileReference(javaDoc));
                            }
                        }
                    }
                }
                entries.add(
                    new org.gradle.plugins.ide.eclipse.model.Library(
                        it.fileReference(new File(projectDir,'/bin'))
                    )
                )
            }
        }
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)