在不使用Gradle编译Groovy源代码的情况下生成groovydoc
我试图从一些groovy代码生成文档,但Gradle失败了,因为它在试图编译代码时无法导入依赖项。这是意料之中的,因为在这些依赖项可用之前,代码需要在特定的上下文中运行。我不知道为什么它甚至试图编译代码,而它似乎只是在解析源代码以提取文档,但这只是一个次要问题 我的身材。格雷德尔:在不使用Gradle编译Groovy源代码的情况下生成groovydoc,gradle,groovy,groovydoc,Gradle,Groovy,Groovydoc,我试图从一些groovy代码生成文档,但Gradle失败了,因为它在试图编译代码时无法导入依赖项。这是意料之中的,因为在这些依赖项可用之前,代码需要在特定的上下文中运行。我不知道为什么它甚至试图编译代码,而它似乎只是在解析源代码以提取文档,但这只是一个次要问题 我的身材。格雷德尔: apply plugin: 'groovy' repositories { mavenCentral(); } dependencies { compile 'org.codehaus.groov
apply plugin: 'groovy'
repositories {
mavenCentral();
}
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.4.5'
}
sourceSets {
main {
groovy {
srcDirs = ['src/org/mysource']
}
}
}
我在
groovyCompile
和CompileGroovy
任务中尝试了各种方法,例如exclude
,但没有什么不同。我无法在此上下文中提供依赖项。欢迎提出其他建议。任何人只要能找到一个使用asciidoc编写groovy文档的可行解决方案,就可以获得额外的积分,我也没能做到这一点。在运行groovydoc
任务时,有两个选项可以禁用:compileGroovy
。首先是一个简短的例子。我有一个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
> Task :groovydoc
Trying to override old definition of task fileScanner
BUILD SUCCESSFUL in 2s
2 actionable tasks: 2 executed
现在让我们仔细看看允许我在不编译这个源的情况下生成GROOVYDOC的选项。
1.从命令行禁用
compileGroovy
运行groovydoc
Gradle任务时,可以使用-x
开关禁用compileGroovy
:
gradle clean groovydoc -x compileGroovy
输出:
> 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
> Task :groovydoc
Trying to override old definition of task fileScanner
BUILD SUCCESSFUL in 2s
2 actionable tasks: 2 executed
2.在
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 executed
感谢您抽出时间提供详细的答案。1.就是这样!我看不见树林,看不见树木。2.这是一个很好的技巧,谢谢。