Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Kenneth A. Kousen - Making Java Groovy - 2014.pdf
Скачиваний:
50
Добавлен:
19.03.2016
Размер:
15.36 Mб
Скачать

124 CHAPTER 5 Build processes

The intro task depends on the hello task from the Ant build, which is imported using the ant variable (an instance of AntBuilder). Running gradle intro executes both tasks:

:hello

[ant:echo] Hello, from Ant :intro

Hello, from Gradle

BUILD SUCCESSFUL

THE WRAPPER TASK

Finally, a client can execute a Gradle build even if they don’t have Gradle installed. Gradle comes with a special Wrapper task, which has a version property:

task wrapper(type: Wrapper) { gradleVersion = '1.6'

}

Running this task generates scripts for both Windows and Unix, called gradlew.bat and gradlew, respectively, along with a minimal Gradle JAR distribution. When executed the wrappers first download and install a local copy of Gradle and then execute the build.

Gradle is a very powerful system, and a thorough investigation is well beyond the scope of this book.13 Hopefully this section will provide you with enough of an introduction to get you started.

Lessons learned (Grapes and Gradle)

1@Grab is helpful for Groovy scripts.

2Gradle uses Groovy build files to configure your build but downloads the internet like Maven.

3Gradle does not have artifacts like Maven, but people are working on ways to create standard builds for various goals.

4In addition to the discussion in this chapter, every project in this book includes a Gradle build highlighting a variety of capabilities.

5.7Summary

This chapter looked at build tools useful for both Groovy and Java projects. Ant is very common but low level. Groovy provides both a raw groovy task and a groovyc compiler task, which can be useful in combined projects.

Maven is a higher-level tool, but it can be difficult to customize. In this chapter I presented both the GMaven project as a way to add Groovy to Maven and the GroovyEclipse plugin approach, which tends to be more robust for cross-compilation issues.

13The book Gradle in Action (Manning, 2013) by Benjamin Muschko is both well written and thorough. I highly recommend it.

www.it-ebooks.info

Summary

125

Groovy includes an @Grab annotation with its so-called Grapes capability, which can be used to add dependencies directly to a Groovy script. It’s powerful, but it’s restricted to Groovy builds.

Finally, I presented the Gradle build tool. This chapter included a basic discussion of Gradle and mentioned several more advanced capabilities. Gradle is used throughout this book to demonstrate interesting mechanisms in each chapter.

www.it-ebooks.info

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]