我正在尝试从某些groovy代码生成文档,但是Gradle失败了,因为它在编译代码时无法导入依赖项。这是预期的,因为在这些依赖项可用之前,该代码需要在特定的上下文中运行。我不知道它为什么要编译代码,因为它似乎应该解析源代码来提取文档,但这是一个附带的问题。
我的build.gradle:
apply plugin: 'groovy'
repositories {
mavenCentral();
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.4.5'
}
sourceSets {
main {
groovy {
srcDirs = ['src/org/mysource']
}
}
}我在groovyCompile和CompileGroovy任务中都尝试过各种东西,比如groovyCompile,但这并没有什么区别。我无法在这个上下文中提供依赖关系。欢迎其他建议。对于任何能够为使用asciidoc编写groovy文档的可行解决方案的人来说,这一点都是额外的,我也没有做到这一点。
发布于 2018-07-14 11:26:48
在运行:compileGroovy任务时,有两个选项可以禁用groovydoc。首先是一个简短的例子。我有一个Groovy项目,在该项目中,我引入了一些使其编译失败的更改:
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的选项。
1.从命令行禁用compileGroovy
在运行-x Gradle任务时,可以使用groovydoc开关禁用groovydoc:
gradle clean groovydoc -x compileGroovy输出:
> Task :groovydoc
Trying to override old definition of task fileScanner
BUILD SUCCESSFUL in 2s
2 actionable tasks: 2 executed2.禁用compileGroovy中的build.gradle
如果您不想使用-x开关,并且希望在运行groovydoc时禁用compileGroovy任务,那么可以通过修改build.gradle中的任务图来禁用compileGroovy
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 executedhttps://stackoverflow.com/questions/51309816
复制相似问题