java - Mavn執(zhí)行測(cè)試時(shí)<scope>test</scope>導(dǎo)致錯(cuò)誤
問(wèn)題描述
學(xué)習(xí)maven test時(shí),執(zhí)行mvn test時(shí),會(huì)找不到org.junit在pom.xml中已經(jīng)引入
<dependencies><dependency> <groupId>joda-time</groupId> <artifactId>joda-time</artifactId> <version>2.2</version></dependency><dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope></dependency> </dependencies>
報(bào)錯(cuò)信息如下文件目錄如下
hello目錄下存在如下文件
其中GreeterTest為測(cè)試
執(zhí)行mvn compile 或者mvn package也會(huì)報(bào)錯(cuò)
當(dāng)把pom.xml中junit依賴(lài)的scope去掉時(shí),編譯和測(cè)試都能成功。
<dependencies><dependency> <groupId>joda-time</groupId> <artifactId>joda-time</artifactId> <version>2.2</version></dependency><dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version></dependency> </dependencies>
造成這個(gè)的原因是什么?maven在執(zhí)行compile時(shí)同時(shí)編譯*Test的文件嗎,那么為什么mvn test也不能成功?mvn test不是會(huì)自動(dòng)執(zhí)行*Test的文件嗎?而且scope test確定了測(cè)試時(shí)會(huì)引入junit
問(wèn)題解答
回答1:這個(gè)問(wèn)題其實(shí)你因?yàn)槟悴皇煜aven文件結(jié)構(gòu)所致.測(cè)試類(lèi)一般是放在src/test/java,而不是放在src/main/java下.maven在編譯的時(shí)候,src/main/java下是不引用<scope>test</scope>的jar,而編譯src/test/java下的測(cè)試這會(huì)引用<scope>test</scope>的jar
相關(guān)文章:
1. sql語(yǔ)句 - mysql中關(guān)聯(lián)表查詢(xún)問(wèn)題2. css - chrome下a標(biāo)簽嵌套img 顯示會(huì)多個(gè)小箭頭?3. javascript - 求解答:實(shí)例對(duì)象調(diào)用constructor,此時(shí)constructor內(nèi)的this的指向?4. javascript - 如何將一個(gè)div始終固定在某個(gè)位置;無(wú)論屏幕和分辨率怎么變化;div位置始終不變5. javascript - vscode alt+shift+f 格式化js代碼,通不過(guò)eslint的代碼風(fēng)格檢查怎么辦。。。6. html - vue項(xiàng)目中用到了elementUI問(wèn)題7. javascript - 有什么比較好的網(wǎng)頁(yè)版shell前端組件?8. javascript - 原生canvas中如何獲取到觸摸事件的canvas內(nèi)坐標(biāo)?9. mysql updtae追加數(shù)據(jù)sql語(yǔ)句10. javascript - iframe 為什么加載網(wǎng)頁(yè)的時(shí)候滾動(dòng)條這樣顯示?
