我在项目的一个文件夹中的 gradle.build 中添加了一个小示例任务:
task fail {
println "ready to fail..."
throw(new Exception("This should not be reached!"))
}
当我尝试提交这个非常 gradle.build 文件时,它失败并显示以下消息:
9:53 Commit failed with error
0 files committed, 1 file failed to commit: A useful commit transaction abort!
rollback completed
abort: The system cannot find the file specified
当我查看日志时,我看到:
Caused by: java.lang.Exception: This should not be reached!
...
2017-07-19 10:22:55,233 [ 247646] INFO - .BaseProjectImportErrorHandler - Failed to import Gradle project at 'C:/Users/543829657/workspace/dev.appl.ib.cbl' org.gradle.tooling.BuildException: Could not run build action using Gradledistribution 'https://services.gradle.org/distributions/gradle-3.2.1-bin.zip'.
Caused by: org.gradle.internal.exceptions.LocationAwareException: Build file 'C:\Users\543829657\workspace\dev.appl.ib.cbl\application\build.gradle' line: 276
...
Caused by: java.lang.Exception: This should not be reached!
...
而且,令人惊讶的是,在日志的末尾出现了关于丢失文件的奇怪消息:
2017-07-19 10:23:05,307 [ 257720] INFO - ea.execution.HgCommandExecutor - hg.exe commit
--logfile C:\Users\543829657\.IntelliJIdea2017.1\system\.hg4idea-commit.tmp application\build.gradle
2017-07-19 10:23:07,655 [ 260068] INFO - ea.execution.HgCommandExecutor - transaction abort!
rollback completed
abort: The system cannot find the file specified
2017-07-19 10:24:38,784 [ 351197] INFO - ea.execution.HgCommandExecutor - hg.exe incoming
2017-07-19 10:24:49,856 [ 362269] INFO - ea.execution.HgCommandExecutor - hg.exe outgoing
2017-07-19 10:27:32,259 [ 524672] INFO - s.plugins.gradle.GradleManager - Instructing gradle to use java from C:/Program Files/Java/jdk1.8.0_72
2017-07-19 10:27:32,299 [ 524712] INFO - s.plugins.gradle.GradleManager - Instructing gradle to use java from C:/Program Files/Java/jdk1.8.0_72
2017-07-19 10:27:32,319 [ 524732] INFO - xecution.GradleExecutionHelper - Passing command-line args to Gradle Tooling API: -Didea.version=2017.1.5
-Didea.resolveSourceSetDependencies=true
-Pandroid.injected.build.model.only=true
-Pandroid.injected.build.model.only.advanced=true
-Pandroid.injected.invoked.from.ide=true
-Pandroid.injected.studio.version=2017.1.5.0.0 --init-script C:\Users\543829657\AppData\Local\Temp\ijinit.gradle
2017-07-19 10:27:33,554 [ 525967] INFO - ntellij.analysis.SonarLintTask - Running SonarLint Analysis for 'build.gradle'
2017-07-19 10:27:33,751 [ 526164] INFO - ntellij.analysis.SonarLintTask - SonarLint analysis done
2017-07-19 10:27:56,522 [ 548935] INFO - pl.ProjectRootManagerComponent - project roots have changed
2017-07-19 10:27:56,835 [ 549248] INFO - .diagnostic.PerformanceWatcher - Pushing properties took 51ms; general responsiveness: ok; EDT responsiveness: ok
2017-07-19 10:27:56,947 [ 549360] INFO - pl.ProjectRootManagerComponent - project roots have changed
2017-07-19 10:27:56,957 [ 549370] INFO - indexing.UnindexedFilesUpdater - Unindexed files update canceled
2017-07-19 10:27:57,084 [ 549497] INFO - .diagnostic.PerformanceWatcher - Pushing properties took 33ms; general responsiveness: ok; EDT responsiveness: ok
2017-07-19 10:27:57,328 [ 549741] INFO - .diagnostic.PerformanceWatcher - Indexable file iteration took 244ms; general responsiveness: ok; EDT responsiveness: ok
2017-07-19 10:29:38,745 [ 651158] INFO - ea.execution.HgCommandExecutor - hg.exe incoming
2017-07-19 10:29:56,117 [ 668530] INFO - ea.execution.HgCommandExecutor - hg.exe outgoing
2017-07-19 10:34:38,752 [ 951165] INFO - ea.execution.HgCommandExecutor - hg.exe incoming
2017-07-19 10:34:54,816 [ 967229] INFO - ea.execution.HgCommandExecutor - hg.exe outgoing
我不希望 IntelliJ 在每次提交之前运行 gradle 任务。另外,我不明白为什么“找不到文件”被声明为失败的原因,而不是真正的原因。
当然,我真的对一个真正的任务有问题,但是现在它被注释掉了,有一个问题是它相对纯粹的状态。这是一个发布任务,显然,我不需要它按照 IDE 的意愿运行。更糟糕的是,它不是从正确的目录启动的,并且由于该问题而创建了无效的文件夹。
PS当然,我试过重启和缓存失效。