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

15.1.1. Forked java processes

Many settings (like the java version and maximum heap size) can only be specified when launching a new JVM for the build process. This means that Gradle must launch a separate JVM process to execute the build after parsing the various gradle.properties files. When running with the daemon, a JVM with the correct parameters is started once and reused for each daemon build execution. When Gradle is executed without the daemon, then a new JVM must be launched for every build execution, unless the JVM launched by the Gradle start script happens to have the same parameters.

This launching of an extra JVM on every build execution is quite expensive, which is why we highly recommend that you use the Gradle Daemon if you are specifying org.gradle.java.home or or

. See Chapter 13, The Gradle Daemon for more details.

15.2. Accessing the web via a proxy

Configuring an HTTP proxy (for example for downloading dependencies) is done via standard JVM system properties. These properties can be set directly in the build script; for example System.set for the proxy host. Alternatively, the properties can be specified in a gradle.properties file, either in the build's root directory or in the Gradle home directory.

Example 15.1. Configuring an HTTP proxy

gradle.properties

systemProp.http.proxyHost=www.somehost.org

systemProp.http.proxyPort=8080

systemProp.http.proxyUser=userid

systemProp.http.proxyPassword=password systemProp.http.nonProxyHosts=*.nonproxyrepos.com|localhost

There are separate settings for HTTPS.

Example 15.2. Configuring an HTTPS proxy

gradle.properties

systemProp.https.proxyHost=www.somehost.org

systemProp.https.proxyPort=8080

systemProp.https.proxyUser=userid

systemProp.https.proxyPassword=password systemProp.https.nonProxyHosts=*.nonproxyrepos.com|localhost

We could not find a good overview for all possible proxy settings. One place to look are the constants in a file from the Ant project. Here a link to the Subversion view. The other is a Networking Properties page from the JDK docs. If anyone knows a better overview, please let us know via the mailing list.

Page 78 of 343

15.2.1. NTLM Authentication

If your proxy requires NTLM authentication, you may need to provide the authentication domain as well as the username and password. There are 2 ways that you can provide the domain for authenticating to a NTLM proxy:

Set the http.proxyUser system property to a value like domain/username. Provide the authentication domain via the http.auth.ntlm.domain system property.

Page 79 of 343

16

Writing Build Scripts

This chapter looks at some of the details of writing a build script.

16.1. The Gradle build language

Gradle provides a domain specific language, or DSL, for describing builds. This build language is based on Groovy, with some additions to make it easier to describe a build.

16.2. The Project API

In the tutorial in Chapter 7, Java Quickstart we used, for example, the apply() method. Where does this method come from? We said earlier that the build script defines a project in Gradle. For each project in the build creates an instance of type Project and associates this Project object with the build script. As the build script executes, it configures this Project object:

Any method you call in your build script, which is not defined in the build script, is delegated to the

Project object.

Any property you access in your build script, which is not defined in the build script, is delegated to the

Project object.

Let's try this out and try to access thename property of the

Project object.

Getting help writing

build scripts

Don't forget that your build script is simply Groovy code that drives the Gradle API. And the Project interface is your starting point for accessing everything in the Gradle API. So, if you're wondering what 'tags' are available in your build script, you can start with the documentation for the Project interface.

Page 80 of 343

Example 16.1. Accessing property of the Project object

build.gradle

println name println project.name

Output of gradle -q check

> gradle -q check projectApi projectApi

Both println statements print out the same property. The first uses auto-delegation to the

Project object, for properties not defined in the build script. The other statement uses the projec property available to any build script, which returns the associated Project object. Only if you define a property or a method which has the same name as a member of the Project object, you need to use the project property.

16.2.1. Standard project properties

The Project object provides some standard properties, which are available in your build script. The following table lists a few of the commonly used ones.

Table 16.1. Project Properties

Name

Type

Default Value

project

Project

The Project instance

name

String

The name of the project directory.

path

String

The absolute path of the project.

description

String

A description for the project.

projectDir

File

The directory containing the build script.

buildDir

File

projectDir/build

group

Object

unspecified

version

Object

unspecified

ant

AntBuilder

An AntBuilder instance

16.3. The Script API

When Gradle executes a script, it compiles the script into a class which implements Script. This means that all of the properties and methods declared by the Script interface are available in your script.

Page 81 of 343

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