LoginSignup
2
4

More than 5 years have passed since last update.

Hamcrest 2.1のリリース

Last updated at Posted at 2018-12-28

概要

Hamcrest 2.1が2018/12/20にリリースされました。
これまでは複数のjarに分割されていたものが、1つのjarに統合されたようです。
公式サイトに、バージョン1.xからのバージョンアップ手順も公開されています。

Hamcrest 公式サイト

主な変更点

  • 前述の通り、jarの提供方法が変わりました。
  • org.hamcrest.Factory アノテーションが削除されました。

Release Note hamcrest-2.1

pom.xmlの書き方

1つだけになったので単純です。

<dependency>
    <groupId>org.hamcrest</groupId>
    <artifactId>hamcrest</artifactId>
    <version>2.1</version>
    <scope>test</scope>
</dependency>

build.gradleの書き方

1つだけなので単純です。

apply plugin: 'java'

dependencies {
    testImplementation 'org.hamcrest:hamcrest:2.1'
}

アップグレード時の注意点

JUnit4はhamcrest-core-1.3.jarに依存している為、そのままではmaven等でうまく依存関係を解消できません。その為、hamcrestでは中身の入っていないhamcrest-core、hamcrest-libraryをリリースすることでこの問題を解決するそうです。

その他のライブラリで同様にhamcrest-core-1.3に依存するものがあれば、下記のような対策を打つことになります。

build.gradleでは、以下のように書きます。

apply plugin: 'java'

dependencies {
    testImplementation 'org.hamcrest:hamcrest:2.1'
    testImplementation 'org.hamcrest:hamcrest-library:2.1'
    testImplementation 'junit:junit:4.12'
}

pom.xmlでは、以下のように書きます。

hamcrest-libraryは他のdependencyより前に記載しないとhamcrest-library 2.1より古いバージョンが利用されてしまう、と公式サイトでは説明されています。

<dependencies>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest</artifactId>
        <version>2.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-library</artifactId>
        <version>2.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
</dependencies>
2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4