開発者ドキュメント

MavenとJUnitの例

Mavenでは、次のようにJUnitの依存関係を宣言できます。

pom.xml

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

しかし、それには `hamcrest-core`ライブラリのバンドル版が付属しています。

$ mvn dependency:tree
...

[INFO]\- junit:junit:jar:4.12:test

[INFO]   \- org.hamcrest:hamcrest-core:jar:1.3:test

...

1. Maven + JUnit + Hamcrest

更新された

pom.xml`をもう一度見てください。これは

hamcrest-core`のJUnitバンドルコピーを除いています。一方、便利な `hamcrest-library`も含まれています:

pom.xml

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.hamcrest</groupId>
                    <artifactId>hamcrest-core</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- This will get hamcrest-core automatically -->
        <dependency>
            <groupId>org.hamcrest</groupId>
            <artifactId>hamcrest-library</artifactId>
            <version>1.3</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

依存関係ツリーをもう一度見直してください。

$ mvn dependency:tree
...

[INFO]+- junit:junit:jar:4.12:test

[INFO]\- org.hamcrest:hamcrest-library:jar:1.3:test

[INFO]   \- org.hamcrest:hamcrest-core:jar:1.3:test

...

参考文献

  1. link://maven/how-to-create-a-java-project-with-maven/[作成する方法

Mavenを使ったJavaプロジェクト]。 link://maven/maven-display-project-dependency/[Maven – プロジェクトを表示する

Mavenで]

モバイルバージョンを終了