Skip to content

Commit ff6d909

Browse files
authored
Merge pull request #255 from domaframework/incremental-annotation-processing
Support Gradle incremental annotation processing
2 parents e2ee7c2 + 85bfbf2 commit ff6d909

File tree

2 files changed

+45
-10
lines changed

2 files changed

+45
-10
lines changed

docs/sources/build.rst

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,28 +74,45 @@ Gradle を使ったビルド
7474

7575
Gradle でビルドを行う際のポイントは以下のとおりです。
7676

77-
* JavaクラスとSQLファイルの出力先ディレクトリを同じにする
78-
* コンパイルより前にSQLファイルを出力先ディレクトリにコピーする
77+
* domaが注釈処理で参照するリソースをテンポラリディレクトリに抽出する
78+
* テンポラリディレクトリ内のリソースをcompileJavaタスクの出力先ディレクトリにコピーする
79+
* テンポラリディレクトリをcompileJavaタスクの入力ディレクトリに設定する
7980
* テスト時は注釈処理を無効にする
8081
* 依存関係の設定でdomaの注釈処理を実行することを示す
81-
* 依存関係の設定でdomaへの依存を指定する
82+
* 依存関係の設定でdomaへの依存を示す
8283

8384
サンプルのbuild.gradleです。
8485

8586
.. code-block:: groovy
8687
8788
apply plugin: 'java'
8889
89-
// JavaクラスとSQLファイルの出力先ディレクトリを同じにする
90-
processResources.destinationDir = compileJava.destinationDir
91-
// コンパイルより前にSQLファイルを出力先ディレクトリにコピーするために依存関係を逆転する
92-
compileJava.dependsOn processResources
90+
// テンポラリディレクトリのパスを定義する
91+
ext.domaResourcesDir = "${buildDir}/tmp/doma-resources"
9392
94-
repositories {
95-
mavenCentral()
96-
maven {url 'https://oss.sonatype.org/content/repositories/snapshots/'}
93+
// domaが注釈処理で参照するリソースをテンポラリディレクトリに抽出
94+
task extractDomaResources(type: Copy, dependsOn: processResources) {
95+
from processResources.destinationDir
96+
include 'doma.compile.config'
97+
include 'META-INF/**/*.sql'
98+
include 'META-INF/**/*.script'
99+
into domaResourcesDir
97100
}
98101
102+
 // テンポラリディレクトリ内のリソースをcompileJavaタスクの出力先ディレクトリにコピーする
103+
task copyDomaResources(type: Copy, dependsOn: extractDomaResources) {
104+
from domaResourcesDir
105+
into compileJava.destinationDir
106+
}
107+
108+
 compileJava {
109+
   // 上述のタスクに依存させる
110+
   dependsOn copyDomaResources
111+
// テンポラリディレクトリをcompileJavaタスクの入力ディレクトリに設定する
112+
  inputs.dir domaResourcesDir
113+
  options.encoding = 'UTF-8'
114+
 }
115+
99116
compileTestJava {
100117
options.encoding = 'UTF-8'
101118
// テストの実行時は注釈処理を無効にする
@@ -109,6 +126,11 @@ Gradle でビルドを行う際のポイントは以下のとおりです。
109126
implementation "org.seasar.doma:doma:2.19.4-SNAPSHOT"
110127
}
111128
129+
repositories {
130+
mavenCentral()
131+
maven {url 'https://oss.sonatype.org/content/repositories/snapshots/'}
132+
}
133+
112134
.. note::
113135

114136
リポジトリにおける https://oss.sonatype.org/content/repositories/snapshots/ の設定は
@@ -117,6 +139,12 @@ Gradle でビルドを行う際のポイントは以下のとおりです。
117139
Doma の SNAPSHOT は `Travis-CI <https://travis-ci.org/domaframework/doma>`_
118140
でビルドが成功されるたびに作成されリポジトリに配置されます。
119141

142+
.. note::
143+
144+
上述のbuild.gradleの書き方により、Gradle 5.0 で導入された
145+
`Incremental annotation processing <https://gradle.org/whats-new/gradle-5/#incremental-annotation-processing>`_ の恩恵を受けられます。
146+
147+
120148
Gradle を使ったより詳細なビルドスクリプトの例として、
121149
`domaframework/simple-boilerplate <https://github.com/domaframework/simple-boilerplate>`_
122150
を参照にしてください。
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
org.seasar.doma.internal.apt.DomainProcessor,isolating
2+
org.seasar.doma.internal.apt.ExternalDomainProcessor,isolating
3+
org.seasar.doma.internal.apt.DomainConvertersProcessor,isolating
4+
org.seasar.doma.internal.apt.EmbeddableProcessor,isolating
5+
org.seasar.doma.internal.apt.EntityProcessor,isolating
6+
org.seasar.doma.internal.apt.DaoProcessor,isolating
7+
org.seasar.doma.internal.apt.SingletonConfigProcessor,isolating

0 commit comments

Comments
 (0)