Doma - ダウンロードからdoma-tutorial-1.14.0をダウンロードして試しました。
m2eclipseインストール済みのeclipseで「Existing Maven Projects」でpom.xmlをインポートしてプロジェクトを作ると
を使ってpom.xmlをeclipseにインポートするとsrc/main/javaがソースディレクトリに登録されない状態になっていました。
Doma - アプリケーションのビルド方法を見ると、javacのバグ回避のためmaven-compiler-pluginでexcludesでソースを除外し、別途maven-antrun-pluginでコンパイルしているそうで、これが原因のようです。
ぐぐってみるとMaven annotation processing with maven-compiler-plugin - Stack Overflowというページを見つけました。maven-compiler-pluginのバージョン2.3.2とbuild-helper-maven-pluginの組み合わせを使えば別途maven-antrun-pluginでコンパイルせずともいけるようです。試してみるとうまくいきました。
この方法だとpom.xmlをインポートしたときにsrc/main/javaもソースパスに含まれます。
この点は解決したのですが、インポート後に以下のようなプロジェクト情報の修正が必要です。
- 一度ビルドしてtarget/apt_generatedディレクトリを作る。
- ソースパスにtarget/apt_generatedを追加。
- ソースパスのsrc/main/resourcesとsrc/test/resroucesのExcludedが*.*になっているのでExcludedの行で[Remove]を押して*.*を(None)に変更。
pom.xmlのdiffをつけておきます。
diff -ruN doma-tutorial-1.14.0.orig/pom.xml doma-tutorial-1.14.0/pom.xml
--- doma-tutorial-1.14.0.orig/pom.xml 2011-03-30 20:25:22.000000000 +0900
+++ doma-tutorial-1.14.0/pom.xml 2011-06-04 09:30:09.865440100 +0900
@@ -108,14 +108,31 @@
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
- <excludes>
- <exclude>**/*</exclude>
- </excludes>
- </configuration>
+ <generatedSourcesDirectory>${project.build.directory}/apt_generated</generatedSourcesDirectory>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <version>1.5</version>
+ <executions>
+ <execution>
+ <phase>generate-sources</phase>
+ <goals>
+ <goal>add-source</goal>
+ </goals>
+ <configuration>
+ <sources>
+ <source>${project.build.directory}/apt_generated</source>
+ </sources>
+ </configuration>
+ </execution>
+ </executions>
</plugin>
</plugins>
</pluginManagement>
@@ -134,6 +151,7 @@
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
+ <version>2.5</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
@@ -156,29 +174,6 @@
</executions>
</plugin>
<plugin>
- <artifactId>maven-antrun-plugin</artifactId>
- <executions>
- <execution>
- <id>ant-compile</id>
- <phase>compile</phase>
- <configuration>
- <tasks>
- <property name="apt_generated" value="target/apt_generated"/>
- <delete dir="${apt_generated}" failonerror="false"/>
- <mkdir dir="${apt_generated}"/>
- <javac fork="yes" compiler="javac1.6" debug="on" encoding="UTF-8"
- classpathref="maven.compile.classpath" srcdir="src/main/java" destdir="target/classes">
- <compilerarg line="-s ${apt_generated}" />
- </javac>
- </tasks>
- </configuration>
- <goals>
- <goal>run</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
<groupId>com.google.code.maven-license-plugin</groupId>
<artifactId>maven-license-plugin</artifactId>
<version>1.4.0</version>
@@ -220,7 +215,7 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
- <version>1.2.126</version>
+ <version>1.3.154</version>
<scope>test</scope>
</dependency>
</dependencies>pom.xmlのインポート時にsrc/main/resourcesとsrc/test/resourcesのExcludedが*.*になってしまう問題については、
[#MNGECLIPSE-864] resources folder are added with "Excluded: **" and this make my tests to fail. - Sonatype JIRAやeclipse - m2eclipse resource filtering - Stack Overflowというページを見つけましたが、解決方法は見つけられませんでした。
[Maven]/[Update Project Configuration]を実行するたびに上記の手順を行う必要があります。
h2はh2-2011-05-27.zipで試したところ1.2.126ではJDBCドライバのバージョンが古いと言われたので1.3.154に変えてあります。
それとDoma - クイックスタートに書かれているcreate table文とinsert文は記述が古いらしくdoma-tutorial-1.14.0のソースとはあっていませんでした。動くようにしたものを以下につけます。insert文の値は適当です。
create sequence employee_seq start with 100 increment by 1;
create table employee (
id integer not null primary key,
name varchar(255) not null,
age integer not null,
salary integer,
job_type varchar(20),
hiredate timestamp,
department_id integer,
version integer not null,
insertTimestamp timestamp,
updateTimestamp timestamp
);
create table department (
id integer not null primary key,
name varchar(255) not null,
version integer not null
);
insert into department values (1, 'Sales', 1);
insert into department values (2, 'Business', 1);
insert into employee values (nextval('employee_seq'), 'SMITH', 45, 800, 'PRESIDENT', '1980-12-17', 1, 1, current_timestamp, current_timestamp);
insert into employee values (nextval('employee_seq'), 'ALLEN', 43, 700, 'MANAGER', '1981-02-20', 1, 1, current_timestamp, current_timestamp);
insert into employee values (nextval('employee_seq'), 'WARD', 40, 600, 'CLERK', '1981-02-22', 2, 1, current_timestamp, current_timestamp);
2 件のコメント:
Domaの作者です。pom.xmlの情報ありがとうございます。取り込みを検討します。
> Doma - クイックスタートに書かれているcreate table文とinsert文は記述が古いらしくdoma-tutorial-1.14.0のソースとはあっていませんでした
クイックスタートとチュートリアルはもとから別物です。ですので、doma-tutorial-1.14.0のソースがクイックスタートと整合性がないのは仕方ないです。
pom.xmlの取り込み検討ありがとうございます。
クイックスタートとチュートリアルは別物だったんですね、失礼しました。
コメントを投稿