【问题标题】:How to detect if gradle plugin is running inside of Intellij如何检测 gradle 插件是否在 Intellij 内部运行
【发布时间】:2021-01-19 06:25:37
【问题描述】:

如何检测 gradle 构建脚本是否在 Intellij 中运行?我想稍微更改项目设置,以优化和解决 IDE 用户的问题。

如果我安装了 Android 插件,那么我可以使用,但没有那个插件就没有明显的钩子。

properties.containsKey('android.injected.invoked.from.ide')

背景:我有一个带有两次源映射的 Gradle 构建,这是因为一个构建 Graal 本机测试启动器的模块。这并不理想,但需要单独讨论,并且涉及各种插件的限制(junit 5 + graal)。

09:38   Duplicate content roots detected
            Path [/home/yschimke/okhttp/okhttp-dnsoverhttps/src/test/java] of module [okhttp-parent.native-image-tests.main] was removed from modules [okhttp-parent.okhttp-dnsoverhttps.test]
            Also 4 more paths were deduplicated. See idea log for details

【问题讨论】:

标签: gradle intellij-idea


【解决方案1】:

来自https://www.baeldung.com/junit-5-conditional-test-execution

在 Mac 和 Windows IDEA_INITIAL_DIRECTORY 上使用 XPC_SERVICE_NAME 环境属性

def isIDE = properties.containsKey('android.injected.invoked.from.ide') ||
        (System.getenv("XPC_SERVICE_NAME") ?: "").contains("intellij")
        (System.getenv("XPC_SERVICE_NAME") ?: "").contains("intellij") ||
        System.getenv("IDEA_INITIAL_DIRECTORY") != null

后者来自https://github.com/JetBrains/intellij-community/blob/f396a4f0777cc1e79908a637f9f814eda794d3f8/native/WinLauncher/WinLauncher/WinLauncher.cpp#L1199

【讨论】:

    【解决方案2】:

    我发现的另一个是,

    isIDEA = System.getProperty("idea.fatal.error.notification") != null
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-17
      • 1970-01-01
      • 2019-07-14
      相关资源
      最近更新 更多