Maven 3 and JUnit 4 compilation problem: package org.junit does not exist

前端 未结 16 1534
时光取名叫无心
时光取名叫无心 2020-12-13 12:06

I am trying to build a simple Java project with Maven. In my pom-file I declare JUnit 4.8.2 as the only dependency. Still Maven insists on using JUnit version 3.8.1. How do

16条回答
  •  鱼传尺愫
    2020-12-13 12:16

    How did you declare the version?

    4.8.2
    

    Be aware of the meaning from this declaration explained here (see NOTES):

    When declaring a "normal" version such as 3.8.2 for Junit, internally this is represented as "allow anything, but prefer 3.8.2." This means that when a conflict is detected, Maven is allowed to use the conflict algorithms to choose the best version. If you specify [3.8.2], it means that only 3.8.2 will be used and nothing else.

    To force using the version 4.8.2 try

    [4.8.2]
    

    As you do not have any other dependencies in your project there shouldn't be any conflicts that cause your problem. The first declaration should work for you if you are able to get this version from a repository. Do you inherit dependencies from a parent pom?

提交回复
热议问题