いろいろ地味に古いけど気にしない。
普通の手順
設定
丁寧な解説ありますけど、もっと雑なの。
pom.xml
のproject/build/plugins
に入れるだけ。
<plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.7.6.201602180812</version> </plugin>
別に入れなくてもいいけど、このくらいは書いた方が楽。
実行
mvn clean jacoco:prepare-agent test
面倒ならexecution
に書く。手順は公式の丁寧な解説を参照。
結果を見る
HTMLで手元で見たいなら jacoco:report
を実行する。
そしたら target/site/jacoco/index.xml
ができる。
Jenkinsにはjacoco.exec
を直接見てもらえば、jacoco:report
は不要。
うまくいかない
test
フェーズを実行してもjacoco.exec
ができなくて、jacoco:report
してたらこんなのが出てたりするとき。
[INFO] --- jacoco-maven-plugin:0.7.6.201602180812:report (default-report) @ xxxxxxxxxxxxxx --- [INFO] Skipping JaCoCo execution due to missing execution data file:/xxxxxxxxxxxxxx/target/jacoco.exec
たぶんmaven-surefire-plugin
になんか設定入ってる。
<plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.19.1</version> <configuration> <argLine>-Xms128m</argLine> </configuration> </plugin>
こっちで書いてると、jacoco:prepare-agent
で設定したargLine
が上書きされてしまう。
なので@{argLine}
で参照しておく。
<plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.19.1</version> <configuration> <argLine>@{argLine} -Xms128m</argLine> </configuration> </plugin>
だいたいはjacoco:prepare-agent
のドキュメントとかに書いてたりするのだけれどね。