Groovy for Domain-specific Languages - Second Edition

(nextflipdebug2) #1

Essential Groovy DSLs


[ 40 ]

This includes some useful tasks as follows:



  • tasks: This lists available tasks as we've seen earlier

  • wrapper: This is a useful way of packaging your Gradle build with a self-
    installing gradle jar

  • projects: This lists the available projects in your build

  • dependencies: This lists the dependencies in your build


The same command run against our hello.gradle example script will also report
the tasks listed in the build script itself: hello, helloSimple, helloWithActions,
and so on. When we run it against the build.gradle script from our previous
examples, it will report they additional tasks provided by the plugins.


Plugins


You will also notice that the script declares three plugins to use, Groovy, IDEA,
and Eclipse. Plugins bundle additional tasks into Gradle that focus on a specific
functionality. By applying these plugins, we are in effect adding additional built-in
tasks to our build that we can call upon.


The Gradle Groovy plugin


The first plugin we have included is the Gradle Groovy plugin. We can see what
additional tasks are applied to our build by running gradle tasks --all in the
sample root directory. The Groovy plugin bundles some useful tasks into our build
to facilitate the compilation, testing, and packaging of the Groovy code. Here are
some of the tasks provided:



  • classes: This task builds the classes from source

  • testClasses: This task builds test classes from source

  • test: This builds all classes and runs the tests

  • clean: This cleans up all target classes and other output files from the build

  • groovydoc: This generates documentation from the JavaDoc style comments
    in Groovy classes


The IDEA plugin


As the name suggests, the IDEA plugin is used to support IntelliJ IDEA. This plugin
provides two main tasks: cleanIdea and idea. These tasks will clear and create the
support files that allow you to view a project in IntelliJ IDEA. Running the following
command from the example source's root will enable you build the project files that
will allow you to view all the sample sources in IDEA:


$gradle cleanIdea idea


http://www.ebook3000.com
Free download pdf