Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Gradle.pdf
Скачиваний:
9
Добавлен:
24.03.2015
Размер:
1.4 Mб
Скачать

54.2. Unix file permissions

The Wrapper task adds appropriate file permissions to allow the execution for the gradlew *NIX command. Subversion preserves this file permission. We are not sure how other version control systems deal with this. What should always work is to execute sh gradlew.

54.3. Environment variable

Some rather exotic use cases might occur when working with the Gradle Wrapper. For example the continuous integration server goes down during unzipping the Gradle distribution. As the distribution directory exists gradlew delegates to it but the distribution is corrupt. Or the zip-distribution was not properly downloaded. When you have no admin right on the continuous integration server to remove the corrupt files, Gradle offers a solution via environment variables.

Table 54.1. Gradle wrapper environment variables

Variable Name

Meaning

GRADLE_WRAPPER_ALWAYS_UNPACK

If set to true, the distribution directory gets

 

always deleted when gradlew is run and the

 

distribution zip is freshly unpacked. If the zip

 

is not there, Gradle tries to download it.

GRADLE_WRAPPER_ALWAYS_DOWNLOAD

If set to true, the distribution directory and

 

the distribution zip gets always deleted

 

when gradlew is run and the distribution zip

 

is freshly downloaded.

Page 325 of 343

55

Embedding Gradle

55.1. Introduction to the Tooling API

The 1.0 milestone 3 release brought a new API called the tooling API, which you can use for embedding Gradle. This API allows you to execute and monitor builds, and to query Gradle about the details of a build. The main audience for this API is IDE, CI server, other UI authors, or integration testing of your Gradle plugins. However, it is open for anyone who needs to embed Gradle in their application.

A fundamental characteristic of the tooling API is that it operates in a version independent way. This means that you can use the same API to work with different target versions of Gradle. The tooling API is Gradle wrapper aware and, by default, uses the same target Gradle version as that used by the wrapper-powered project.

Some features that the tooling API provides today:

You can query Gradle for the details of a build, including the project hierarchy and the project dependencies, external dependencies (including source and javadoc jars), source directories and tasks of each project.

You can execute a build, and listen to stdout and stderr logging and progress (e.g. the stuff shown in the 'status bar' when you run on the command line).

Tooling API can download and install the appropriate Gradle version, similar to the wrapper. Bear in mind that the tooling API is wrapper aware so you should not need to configure a Gradle distribution directly.

The implementation is lightweight, with only a small number of dependencies. It is also a well-behaved library, and makes no assumptions about your class loader structure or logging configuration. This makes the API easy to bundle in your application.

In future we may support other interesting features:

Performance. The API gives us the opportunity to do lots of caching, static analysis and preemptive work, to make things faster for the user.

Better progress monitoring and build cancellation. For example, allowing test execution to be monitored.

Notifications when things in the build change, so that UIs and models can be updated. For example, your Eclipse or IDEA project will update immediately, in the background.

Page 326 of 343

Validating and prompting for user supplied configuration.

Prompting for and managing user credentials.

The Tooling API is the official and recommended way to embed Gradle. This means that the existing APIs, namely GradleLauncher and the open API (the UIFactory and friends), are mildly deprecated and will be removed in some future version of Gradle. If you happen to use one of the above APIs, please consider changing your application to use the tooling API instead.

55.2. Tooling API and the Gradle Build Daemon

Please take a look at Chapter 13, The Gradle Daemon. The Tooling API uses the daemon all the time, e.g. you cannot officially use the Tooling API without the daemon. This means that subsequent calls to the Tooling API, be it model building requests or task executing requests can be executed in the same long-living process. Chapter 13, The Gradle Daemon contains more details about the daemon, specifically information on situations when new daemons are forked.

55.3. Quickstart

Since the tooling API is an interface for a programmer most of the documentation lives in Javadoc/Groovydoc. This is exactly our intention - we don't expect this chapter to grow very much Instead we will add more code samples and improve the Javadoc documentation. The main entry point to the tooling API is the GradleConnector. You can navigate from there and find code samples and other instructions. Pretty effective way of learning how to use the tooling API is checking out and running the samples that live in $gradleHome/samples/toolingApi.

If you're embedding Gradle and you're looking for exact set of dependencies the tooling API J requires please look at one of the samples in $gradleHome/samples/toolingApi. The dependencies are declared in the Gradle build scripts. You can also find the repository declarations where the Jars are obtained from.

Page 327 of 343

A

Gradle Samples

Listed below are some of the stand-alone samples which are included in the Gradle distribution. You can find these samples in the GRADLE_HOME/samples directory of the distribution.

Table A.1. Samples included in the distribution

Sample

Description

announce

A project which uses the announce plugin

application

A project which uses the application plugin

codeQuality

A project which uses the various code quality plugins.

customBuildLanguage

This sample demonstrates how to add some custom

 

elements to the build DSL. It also demonstrates the use

 

of custom plug-ins to organize build logic.

customDistribution

This sample demonstrates how to create a custom

 

Gradle distribution and use it with the Gradle wrapper.

customPlugin

A set of projects that show how to implement, test,

 

publish and use a custom plugin and task.

ear/earCustomized/ear

Web application ear project with customized contents

ear/earWithWar

Web application ear project

groovy/customizedLayout

Groovy project with a custom source layout

groovy/mixedJavaAndGroovy

Project containing a mix of Java and Groovy source

Page 328 of 343

groovy/multiproject

Build made up of multiple Groovy projects. Also

 

demonstrates how to exclude certain source files, and the

 

use of a custom Groovy AST transformation.

groovy/quickstart

Groovy quickstart sample

java/base

Java base project

java/customizedLayout

Java project with a custom source layout

java/multiproject

This sample demonstrates how an application can be

 

composed using multiple Java projects.

java/quickstart

Java quickstart project

java/withIntegrationTests

This sample demonstrates how to use a source set to

 

add an integration test suite to a Java project.

maven/pomGeneration

Demonstrates how to deploy and install to a Maven

 

repository. Also demonstrates how to deploy a javadoc

 

JAR along with the main JAR, how to customize the

 

contents of the generated POM, and how to deploy

 

snapshots and releases to different repositories.

maven/quickstart

Demonstrates how to deploy and install artifacts to a

 

Maven repository.

osgi

A project which builds an OSGi bundle

scala/customizedLayout

Scala project with a custom source layout

scala/fsc

Scala project using the Fast Scala Compiler (fsc).

scala/mixedJavaAndScala

A project containing a mix of Java and Scala source.

scala/quickstart

Scala quickstart project

toolingApi/build

An application which uses the tooling API to execute a

 

Gradle build.

toolingApi/eclipse

An application which uses the tooling API to build the

 

Eclipse model for a project.

Page 329 of 343

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