第20章 ビルド環境

20.1. gradle.propertiesを使用したビルド環境の構築Configuring the build environment via gradle.properties

Gradle provides several options that make it easy to configure the Java process that will be used to execute your build. While it's possible to configure these in your local environment via GRADLE_OPTS or JAVA_OPTS, certain settings like JVM memory settings, Java home, daemon on/off can be more useful if they can be versioned with the project in your VCS so that the entire team can work with a consistent environment. Setting up a consistent environment for your build is as simple as placing these settings into a gradle.properties file. The configuration is applied in following order (if an option is configured in multiple locations the last one wins): (in case an option is configured in multiple locations the last one wins): Gradleでは、ビルドを実行するJavaプロセスの設定を簡単に変更するための方法が複数用意されています。 ローカルの環境変数でGRADLE_OPTSやJAVA_OPTSを使って設定することもできますが、一部の設定値、JVMメモリ設定やJava home、デーモンのオンオフなどについてはプロジェクトのVCSに格納してバージョン管理しておけば、チームメンバー全員が一貫した環境で作業することができるので便利です。 こうした一貫した設定値は、gradle.propertiesに設定値を保存するだけで実現可能です。 設定値は以下の順序で適用されます(複数箇所で設定されている場合は最後の一つが優先されます)。

  • from gradle.properties located in project build dir. プロジェクトのビルドディレクトリに置かれたgradle.properties
  • from gradle.properties located in gradle user home.gradleユーザーホームディレクトリに置かれたgradle.properties
  • from system properties, e.g. when -Dsome.property is used in the command line.-Dsome.propertyなどで指定されたシステムプロパティ

The following properties can be used to configure the Gradle build environment: 以下のプロパティがGradleのビルド環境を設定するために使用されます。

org.gradle.daemon

When set to true the Gradle daemon is used to run the build. For local developer builds this is our favorite property. The developer environment is optimized for speed and feedback so we nearly always run Gradle jobs with the daemon. We don't run CI builds with the daemon (i.e. a long running process) as the CI environment is optimized for consistency and reliability.

trueに設定するとデーモンによりビルドが実行されます。 開発者がローカルでビルドを実行する際は、このプロパティを設定することをおすすめします。開発環境ではスピードやフィードバックという点を重視したいので、私たちもほとんどいつもデーモンを使ってGradleのジョブを走らせています。 一方、CI環境では並行性、信頼性といった点を重視したいため、CIビルド(というか実行時間の長い処理)でデーモンを使うことはありません。

org.gradle.java.home

Specifies the Java home for the Gradle build process. The value can be set to either a jdk or jre location, however, depending on what your build does, jdk is safer. A reasonable default is used if the setting is unspecified.

Gradleのビルドシステムで使用するJava homeを指定します。 設定するのはjdkでもjre構いませんが、プロジェクトによってはjdkを指定した方が安全かもしれません。 指定しなければ、適当なデフォルト値が設定されます。

org.gradle.jvmargs

Specifies the jvmargs used for the daemon process. The setting is particularly useful for tweaking memory settings. At the moment the default settings are pretty generous with regards to memory.

デーモンプロセスに渡すJVM引数を指定します。 この設定はメモリ設定を調節するのに特に便利です。 デフォルト値はメモリに応じて適切に設定されます。

org.gradle.configureondemand

Enables new incubating mode that makes Gradle selective when configuring projects. Only relevant projects are configured which results in faster builds for large multi-projects. See 「Configuration on demand」.

Gradleがプロジェクトを選択的に設定する試験的なモードを有効にします。 関係のあるプロジェクトのみを評価することで、巨大なマルチプロジェクト・ビルドをより高速にビルドできるようにします。 詳しくは「Configuration on demand」を参照してください。

org.gradle.parallel

When configured, Gradle will run in incubating parallel mode.

この設定を行うと、Gradleの試験的な並列ビルドモードが有効化されます。

20.1.1. Javaプロセスのフォーク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.

JVMに関する設定の多く(Javaバージョンや最大ヒープサイズなど)は、新しくJVMプロセスを起動するときのみ設定できます。 これはつまり、Gradleが解析した多様なgradle.propertiesに従ってビルドを実行するには、JVMプロセスを新しく起動しなければならないということを意味します。 デーモンを実行しているときは、適切なパラメーターが設定されたJVMが起動され、デーモンごとに再利用されます。 デーモンを使用せずにビルドを実行したときは、Gradleのスタートスクリプトが起動したJVMとたまたま同じパラメーターでビルドするのでない限り、ビルドの度に新しくJVMを起動しなければなりません。

This launching of an extra JVM on every build execution is quite expensive, which is why if you are setting either org.gradle.java.home or org.gradle.jvmargs we highly recommend that you use the Gradle Daemon. See 19章Gradleデーモン for more details.

ビルドを実行する度にJVMを余分に起動しなければならないというのは、とても大きなコストになります。なので、org.gradle.java.homeorg.gradle.jvmargsを設定しているのであればGradleデーモンを使ってビルドすることを強く推奨します。詳細については19章Gradleデーモン を参照してください。

20.2. プロクシ経由のWebアクセスAccessing the web via a proxy

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

(例えば依存関係のダウンロードするための)HTTPプロクシの設定は 標準的なJVMのシステムプロパティを使って行います。これらの設定は、直接ビルドスクリプト上で設定することが可能です。 例えばプロクシのホストの為に System.setProperty('http.proxyHost', 'www.somehost.org')と設定できます。 あるいは、ビルドのルートディレクトリ上 又は Gradleホームディレクトリ上にある gradle.propertiesファイルにそれらの値を設定できます。

例20.1 HTTPプロクシの設定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.

HTTPS設定の分離

例20.2 HTTPSプロクシの設定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's a link to the Subversion view. The other is a Networking Properties page from the JDK docs. If anyone knows of a better overview, please let us know via the mailing list.

使用可能な全てのプロクシ設定を概観できる良い資料については残念ながら発見することができませんでした。一つの情報源は、Antプロジェクトのファイルに定義された定数です。 Subversionへのリンク を載せておきます。他には、JDKドキュメントに ネットワーク設定値のページ がありました。 その他、もっと良い資料をご存知であれば、メーリングリストでお知らせください。

20.2.1. NTLM認証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: NTLM認証が必要なプロクシを使う場合、ユーザ名とパスワードだけでなく認証ドメインを設定する必要があります。ドメインを設定する方法には以下の二つがあります。

  • Set the http.proxyUser system property to a value like domain/username. システムプロパティhttp.proxyUserに、domain/usernameのように値を設定する。
  • Provide the authentication domain via the http.auth.ntlm.domain system property. システムプロパティhttp.auth.ntlm.domainに認証ドメインを設定する。