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

前端 未结 16 1513
时光取名叫无心
时光取名叫无心 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:25

    I also ran into this issue - I was trying to pull in an object from a source and it was working in the test code but not the src code. To further test, I copied a block of code from the test and dropped it into the src code, then immediately removed the JUnit lines so I just had how the test was pulling in the object. Then suddenly my code wouldn't compile.
    The issue was that when I dropped the code in, Eclipse helpfully resolved all the classes so I had JUnit calls coming from my src code, which was not proper. I should have noticed the warnings at the top about unused imports, but I neglected to see them.
    Once I removed the unused JUnit imports in my src file, it all worked beautifully.

提交回复
热议问题