:compileGroovy
在运行groovydoc
任务时,您有两个选项可以禁用。首先是一个简短的例子。我有一个 Groovy Gradle 项目,我在其中引入了一些使其编译失败的更改:
gradle groovydoc
输出:
> Task :compileGroovy FAILED
startup failed:
/home/wololock/workspace/upwork/jenkins-continuous-delivery-pipeline/src/com/upwork/util/MapUtils.groovy: 29: [Static type checking] - Cannot find matching method com.upwork.util.MapUtils#merge(V, java.lang.Object). Please check if the declared type is right and if the method exists.
@ line 29, column 56.
= result[k] instanceof Map ? merge(resu
^
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileGroovy'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 4s
1 actionable task: 1 executed
现在让我们仔细看看允许我在不编译此源代码的情况下生成 groovydoc 的选项。
compileGroovy
1.从命令行禁用
您可以在运行Gradle 任务时使用-x
switch 来禁用:compileGroovy
groovydoc
gradle clean groovydoc -x compileGroovy
输出:
> Task :groovydoc
Trying to override old definition of task fileScanner
BUILD SUCCESSFUL in 2s
2 actionable tasks: 2 executed
compileGroovy
2.禁用build.gradle
如果您不想使用-x
switch 并且您希望compileGroovy
在运行时groovydoc
禁用任务,那么您可以compileGroovy
通过修改以下任务图来禁用build.gradle
:
gradle.taskGraph.whenReady { graph ->
if (graph.hasTask(':groovydoc')) {
compileGroovy.enabled = false
}
}
只需将其添加到build.gradle
文件中的某个位置即可。现在当你执行:
gradle groovydoc
该任务compileGroovy
将被禁用并且源代码不会被编译。
> Task :groovydoc
Trying to override old definition of task fileScanner
BUILD SUCCESSFUL in 2s
2 actionable tasks: 2 executed