付録A Gradleサンプル集 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.

Gradleの配布物には、スタンドアローンで動作するサンプルが含まれています。以下にその一覧を掲載しました。これらのサンプルは、配布物の GRADLE_HOME/samples ディレクトリに入っています。

表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 アプリケーションプラグインを使うプロジェクト

buildDashboard

A project which uses the build-dashboard 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. ビルドDSLへカスタム要素を追加するデモです。カスタムプラグインを使ってビルドロジックを体系化するデモでもあります。

customDistribution

This sample demonstrates how to create a custom Gradle distribution and use it with the Gradle wrapper. Gradleのカスタムディストリビューションを作る方法、およびそのディストリビューションをGradleラッパーで使う方法をデモしています。

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 中身をカスタマイズしたWebアプリケーションearプロジェクト

ear/earWithWar

Web application ear project Webアプリケーションearプロジェクト

groovy/customizedLayout

Groovy project with a custom source layout ソースコードのレイアウトをカスタマイズしたGroovyプロジェクト

groovy/mixedJavaAndGroovy

Project containing a mix of Java and Groovy source JavaとGroovyのソースが混ざって含まれているプロジェクト

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プロジェクトで構成されたビルド。特定のソースファイルを除外する方法、およびGroovyのカスタムAST変換を使う方法を示すデモでもあります。

groovy/quickstart

Groovy quickstart sample Groovyクイックスタートサンプル

java/base

Java base project 基本的なJavaプロジェクト

java/customizedLayout

Java project with a custom source layout ソースコードのレイアウトをカスタマイズしたJavaプロジェクト

java/multiproject

This sample demonstrates how an application can be composed using multiple Java projects. 複数のJavaプロジェクトを使ってアプリケーションを組み立てるデモ

java/quickstart

Java quickstart project Javaクイックスタートプロジェクト

java/withIntegrationTests

This sample demonstrates how to use a source set to add an integration test suite to a Java project. ソースセットを使って、Javaプロジェクトに結合テスト・スイートを追加する方法を示すサンプル

javaGradlePlugin

This example demonstrates the use of the java gradle plugin development plugin. By applying the plugin, the java plugin is automatically applied as well as the gradleApi() dependency. Furthermore, validations are performed against the plugin metadata during jar execution.

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リポジトリにデプロイ、インストールするデモ。メインのJARに加えてJavaDocのJARをデプロイしたり、生成されるPOMの内容をカスタマイズしたり、スナップショットとリリース版を違うリポジトリにデプロイしたりもしています。

maven/quickstart

Demonstrates how to deploy and install artifacts to a Maven repository. Mavenリポジトリにアーティファクトをデプロイ、インストールするデモ

osgi

A project which builds an OSGi bundle OSGiバンドルをビルドするプロジェクト

scala/customizedLayout

Scala project with a custom source layout ソースコードのレイアウトをカスタマイズしたScalaプロジェクト

scala/fsc

Scala project using the Fast Scala Compiler (fsc). Fast Scala Compiler (fsc)を使ったScalaプロジェクト

scala/mixedJavaAndScala

A project containing a mix of Java and Scala source. ScalaとJavaのソースが混ざって含まれているプロジェクト

scala/quickstart

Scala quickstart project Scalaクイックスタートプロジェクト

scala/zinc

Scala project using the Zinc based Scala compiler.

testing/testReport

Generates an HTML test report that includes the test results from all subprojects.

toolingApi/customModel

A sample of how a plugin can expose its own custom tooling model to tooling API clients.

toolingApi/eclipse

An application that uses the tooling API to build the Eclipse model for a project. Tooling APIを使ってEclipseのプロジェクトモデルを構築するアプリケーション

toolingApi/idea

An application that uses the tooling API to extract information needed by IntelliJ IDEA. IntellJ IDEAで必要な情報を、Tooling APIを使って抽出するアプリケーション

toolingApi/model

An application that uses the tooling API to build the model for a Gradle build.

toolingApi/runBuild

An application that uses the tooling API to run a Gradle task.

userguide/distribution

A project which uses the distribution plugin

userguide/javaLibraryDistribution

A project which uses the Java library distribution plugin

webApplication/customized

Web application with customized WAR contents. 中身をカスタマイズしたWARをビルドするWebアプリケーションプロジェクト

webApplication/quickstart

Web application quickstart project Webアプリケーション クイックスタートプロジェクト

A.1. サンプル Sample 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. ビルドDSLへカスタム要素を追加するデモです。カスタムプラグインを使ってビルドロジックを体系化するデモでもあります。

The build is composed of 2 types of projects. The first type of project represents a product, and the second represents a product module. Each product includes one or more product modules, and each product module may be included in multiple products. That is, there is a many-to-many relationship between these products and product modules. For each product, the build produces a ZIP containing the runtime classpath for each product module included in the product. The ZIP also contains some product-specific files.

このビルドは、二種類のプロジェクトから構成されています。「製品」プロジェクトと「製品モジュール」プロジェクトです。 「製品」は複数の「製品モジュール」から構成されており、ひとつの「製品モジュール」は複数のプロジェクトに含まれる可能性があります。 つまり、「製品モジュール」とプロジェクトが、多対多の関係になっているのです。 各「製品」は、「製品モジュール」の実行時クラスパスを固めたZIPファイルを作成します。さらに、ZIPファイルには「製品」が指定したファイルも格納されます。

The custom elements can be seen in the build script for the product projects (for example, basicEdition/build.gradle). Notice that the build script uses the product { } element. This is a custom element.

「製品」プロジェクトのビルドスクリプト(basicEdition/build.gradleなど)では、独自のカスタム要素が使用されています。ビルドスクリプトで、product { }という要素が使われていることに注目してください。これがカスタム要素です。

The build scripts of each project contain only declarative elements. The bulk of the work is done by 2 custom plug-ins found in buildSrc/src/main/groovy.

プロジェクトのビルドスクリプトには、要素の宣言しか含まれていません。処理の大半はbuildSrc/src/main/groovyにある二つのカスタムプラグインで記述されています。

A.2. サンプル Sample customDistribution

This sample demonstrates how to create a custom Gradle distribution and use it with the Gradle wrapper. Gradleのカスタムディストリビューションを作る方法、およびそのディストリビューションをGradleラッパーで使う方法をデモしています。

This sample contains the following projects:

このサンプルには次のプロジェクトが含まれています。

  • The plugin directory contains the project that implements a custom plugin, and bundles the plugin into a custom Gradle distribution.

    pluginディレクトリに入っているプロジェクトで、カスタムプラグインを実装してディストリビューションにバンドルしています。

  • The consumer directory contains the project that uses the custom distribution.

    consumerディレクトリに入っているプロジェクトで、そのカスタムディストリビューションを使用しています。

A.3. サンプル Sample customPlugin

A set of projects that show how to implement, test, publish and use a custom plugin and task. カスタムプラグインやカスタムタスクの実装、テスト、公開および使用方法を示す、いくつかのサンプルプロジェクト

This sample contains the following projects:

このサンプルには、以下のプロジェクトが含まれています。

  • The plugin directory contains the project that implements and publishes the plugin.

    pluginディレクトリのプロジェクトで、プラグインを実装して公開しています。

  • The consumer directory contains the project that uses the plugin.

    consumerディレクトリのプロジェクトで、そのプラグインを使用しています。

A.4. サンプル Sample java/multiproject

This sample demonstrates how an application can be composed using multiple Java projects. 複数のJavaプロジェクトを使ってアプリケーションを組み立てるデモ

This build creates a client-server application which is distributed as 2 archives. First, there is a client ZIP which includes an API JAR, which a 3rd party application would compile against, and a client runtime. Then, there is a server WAR which provides a web service.

このビルドはクライアント・サーバー型のアプリケーションを作成するもので、配布物になるのは二つのアーカイブです。 サードパーティ製のアプリケーションをコンパイルするためのAPIを含むJARとクライアントのランタイムが入ったZIPファイル、 そして、Webサービスを提供するサーバーWARファイルを作成します。