Chapter 9. Groovy Quickstart 快速开始 Groovy

    让我们来看一个例子。要使用 Groovy 插件,你需要在构建脚本文件当中添加以下内容

    Example 9.1. Groovy plugin

    build.gradle

    同时会将 Java 插件应用到项目中,如果还没有应用的话。Groovy 插件 继承自 compile task 在 src/main/groovy 目录中查找源文件;且继承了 compileTest task,在 src/test/groovy 目录中查找测试的源文件。这些编译 task 对这些目录使用了联合编译,这意味着它们可以同时包含 Java 和 Groovy 源文件。

    Example 9.2. Dependency on Groovy

    build.gradle

    Example 9.3. Groovy example - complete build file

    build.gradle

    运行 将会对你的项目进行编译,测试和打成 JAR 包。

    9.2. Summary 总结

    你可以参阅 去了解更多关于 Groovy 插件的内容,或在 https://github.com/waylau/Gradle-2-User-Guide-Demos 中 groovy 目录中找到更多的 Groovy 项目示例。