【问题标题】:What command does Intellij Gradle project refresh executeIntellij Gradle 项目刷新执行什么命令
【发布时间】:2019-11-29 14:16:32
【问题描述】:

每当您按下按钮以使用 gradle 执行某些操作时,Intellij 都会隐藏它运行的 gradle 命令。这使得很难找出问题所在。我正在单击“刷新”(不刷新依赖项),它似乎触发了我所有的兄弟项目和我的项目构建这是错误的。它绝对没有运行“gradle build”,因为如果它运行了,它不会触发我的多项目构建中的所有兄弟项目。

【问题讨论】:

  • "> 很难找出问题所在" 那么究竟出了什么问题呢?我认为 IDEA 不会“运行”任何命令行,而是使用 gradle API 执行 gradle 的配置阶段。正确的是,它会导致在多项目设置中考虑所有子项目。
  • IDE 在使用 Gradle 项目模型时使用 Gradle Tooling API。您可以将 Gradle 项目添加到 Gradle 工具窗口中的忽略列表中,以不触发它的 gradle 刷新。

标签: intellij-idea gradle


【解决方案1】:

在gradle中点击“刷新”会出现这样的日志:

2019-10-17 14:58:10,391 [9949323]   INFO - xecution.GradleExecutionHelper - Passing command-line args to Gradle Tooling API: -Didea.sync.active=true -Didea.resolveSourceSetDependencies=true --init-script /tmp/ijinit.gradle

这里 IDEA 使用 Gradle Tooling API 并使用 gradle init script(在我的机器上的 /tmp/ijinit.gradle 中)。该文件显示更多:

$ cat /tmp/ijinit.gradle

...imports etc...

initscript {
  dependencies {
    classpath files([...list of IDEA jars...])
  }
}

apply plugin: JetGradlePlugin

class JetGradlePlugin implements Plugin<Gradle> {
  void apply(Gradle gradle) {
    def processor = new RegistryProcessor()
    gradle.addProjectEvaluationListener(processor)
    def projectEvaluationIsNotCalledForIncludedBuilds = GradleVersion.current() >= GradleVersion.version("3.1") &&
                                                        GradleVersion.current() < GradleVersion.version("4.0")
    if (projectEvaluationIsNotCalledForIncludedBuilds) {
      gradle.rootProject {
        it.afterEvaluate {
          gradle.includedBuilds.each { included ->
            // included builds should be configured by now, so calling `configuredBuild` should be safe
            def toolingRegistry = (ToolingModelBuilderRegistry)included.configuredBuild.services.get(ToolingModelBuilderRegistry.class)
            processor.process(toolingRegistry)
          }
        }
      }
    }
  }
}
...other overrides...

正如其他人提到的,可以在 IDEA Gradle 选项卡中排除包含的构建,但希望这能回答具体的标题问题。

【讨论】:

    【解决方案2】:

    如果您使用的是最新版本的 Gradle,则可以使用 --refresh-dependencies 选项。

    ./gradlew build --refresh-dependencies

    【讨论】:

      猜你喜欢
      • 2019-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-07
      • 1970-01-01
      • 2014-12-11
      相关资源
      最近更新 更多