2017-04-22 55 views
0

我正在用java 9(build 9-ea + 165)構建一個使用maven 3.3.9的項目。測試運行並且構建成功。如何在JDK 9中爲IntelliJ添加測試依賴關係?

但是, IntelliJ Idea 2017.1.2抱怨並且不會通過消息'該模塊在其需求中沒有模塊'junit.jupiter.api'來編譯/運行測試。

如何爲IntelliJ添加此項? 是否有必要?

截圖: Screenshot from editor in IntelliJ.

項目結構: Project structure

從POM:

<dependencies> 
    <!-- testing --> 
    <dependency> 
     <groupId>org.hamcrest</groupId> 
     <artifactId>hamcrest-all</artifactId> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.junit.jupiter</groupId> 
     <artifactId>junit-jupiter-api</artifactId> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>org.mockito</groupId> 
     <artifactId>mockito-core</artifactId> 
     <scope>test</scope> 
    </dependency> 
</dependencies> 
<build> 
    <pluginManagement> 
     <plugins> 
      <plugin> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.6.1</version> 
       <configuration> 
        <source>9</source> 
        <target>9</target> 
        <showWarnings>true</showWarnings> 
        <showDeprecation>true</showDeprecation> 
       </configuration> 
      </plugin> 
      <plugin> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <version>2.19</version> 
       <dependencies> 
        <dependency> 
         <groupId>org.junit.platform</groupId> 
         <artifactId>junit-platform-surefire-provider</artifactId> 
         <version>1.0.0-M4</version> 
        </dependency> 
        <dependency> 
         <groupId>org.junit.vintage</groupId> 
         <artifactId>junit-vintage-engine</artifactId> 
         <version>4.12.0-M4</version> 
        </dependency> 
       </dependencies> 
      </plugin> 
     </plugins> 
    </pluginManagement> 

    <plugins> 
     <plugin> 
      <artifactId>maven-compiler-plugin</artifactId> 
     </plugin> 
     <plugin> 
      <artifactId>maven-surefire-plugin</artifactId> 
     </plugin> 
    </plugins> 
</build> 
+0

請分享消息的確切消息或屏幕截圖,還有什麼測試依賴關係是否使用? – nullpointer

+0

你用java 8試過嗎?你的來源可能嗎?也許只是爲了檢查它是否修復了測試中的依賴關係,即使它不能編譯和運行你的代碼 –

+0

你是否檢查過你的maven緩存中有相關的jar包?通常〜/ .m2/repository/... –

回答

0

這有可能是你的項目結構不再有效。您可以嘗試檢查包含您的測試的文件夾是否爲您的實際測試文件夾:

  1. 按下[Ctrl] [Alt] [Shift] [S]打開Project Structure。
  2. 打開「模塊」
  3. 打開「源標籤」包含測試
  4. 你的文件夾應被標記爲「測試」(圖標爲綠色)
+0

項目結構良好,Joost Verbraeken。文件夾src/main/java是藍色的,標記爲源文件夾,src/test/java爲綠色並標記爲測試源文件夾... – TEJacobsen

0

有幾個選項

首先,您可能尚未將項目正確導入到IntelliJ中。在這種情況下,要做的最快的事情往往是簡單地關閉項目,從源目錄(.idea目錄和任何*.i?l文件)中刪除intellij文件,並使用open選項重新打開相應的根文件夾文件(如果它給你的該選項,選擇創建一個新項目並刪除舊項目)。

第二種選擇是你已經正確地打開了項目,但你沒有重新導入它,因爲改變了pom,並且你沒有啓用自動導入,並且忽略了要求你重新加載的通知。在這種情況下,只需打開maven窗口(通常從屏幕右側的水平按鈕),然後點擊maven窗口左上角的重新導入按鈕。

第三個選項是吹走你的緩存。這很容易從文件菜單完成。

可能有其他的。我會從頭開始。

+0

首先:我關閉了項目。 idea文件夾並刪除了任何* .i?l文件。使用項目的根目錄導入項目更多......但沒有雪茄:(......第二和第三:我刷新了所有Maven項目,並且嘗試使我的緩存無效並重新啓動IntelliJ,但仍然沒有雪茄...... :(我不認爲第二個和第三個選項應該以任何方式提供幫助,因爲我無法首先導入項目... – TEJacobsen

相關問題