2015-04-03 8 views
1

在多個目標上運行./pants idea時,生成的IntelliJ項目允許我引用目標實際上不依賴的代碼。當運行帶有多個目標的./pants理念時,爲什麼IntelliJ不尊重我的依賴關係?

下面是

./pants idea examples/tests/java/com/pants/examples/hello/greet:: \ 
    examples/tests/java/com/pants/examples/useproto:: 

在Greeting.java,我添加上Hello項目,實際上並不取決於一些依賴褲子爲例:

public static String greet(String greetee) { 
    // These two lines added to illustrate question 
    Distance proto = Distance.getDefaultInstance(); 
    System.out.println("Proto: " + proto.toString()); 
    return "Hello, " + greetee + "!"; 
    } 

GreetingTest項目在IntelliJ下運行良好!

當我嘗試從命令行運行GreetingTest時,它失敗。

$ ./pants test examples/tests/java/com/pants/examples/hello/greet 
INFO] Detected git repository at /Users/zundel/Src/pants on branch master 

11:24:20 00:00 [main] 
       (To run a reporting server: ./pants server) 
11:24:20 00:00 [bootstrap] 
11:24:20 00:00 [setup] 
11:24:20 00:00  [parse] 
       Executing tasks in goals: bootstrap -> imports -> unpack-jars -> deferred-sources -> gen -> resolve -> compile -> resources -> test 
11:24:20 00:00 [bootstrap] 
11:24:20 00:00  [bootstrap-jvm-tools] 
11:24:20 00:00 [imports] 
11:24:20 00:00  [ivy-imports] 
11:24:20 00:00 [unpack-jars] 
11:24:20 00:00  [unpack-jars] 
11:24:20 00:00 [deferred-sources] 
11:24:20 00:00  [deferred-sources] 
11:24:20 00:00 [gen] 
11:24:20 00:00  [thrift] 
11:24:20 00:00  [protoc] 
11:24:20 00:00  [antlr] 
11:24:20 00:00  [ragel] 
11:24:20 00:00  [jaxb] 
11:24:21 00:01  [wire] 
11:24:21 00:01  [aapt] 
11:24:21 00:01  [scrooge] 
11:24:21 00:01 [resolve] 
11:24:21 00:01  [ivy] 
        Invalidated 2 targets. 
11:24:21 00:01  [ivy-resolve] 
11:24:21 00:01 [compile] 
11:24:21 00:01  [compile] 
11:24:21 00:01  [jvm] 
11:24:21 00:01  [jvm-compilers] 
11:24:21 00:01   [find-deleted-sources] 
        Invalidated 2 targets. 
11:24:21 00:01   [partition-analysis] 
        Compiling 2 java sources in 2 targets (partition 1 of 1). 
11:24:21 00:01   [compile] 
11:24:21 00:01   [jmake] 
         Jmake version 1.3.8-10 
         Opening project database... Done. 
         Recompiling source files: 
         /Users/zundel/Src/pants/examples/src/java/com/pants/examples/hello/greet/Greeting.java 
         /Users/zundel/Src/pants/examples/src/java/com/pants/examples/hello/greet/Greeting.java:6: error: package com.pants.examples.distance.Distances does not exist 
         import com.pants.examples.distance.Distances.Distance; 
                    ^
         /Users/zundel/Src/pants/examples/src/java/com/pants/examples/hello/greet/Greeting.java:37: error: cannot find symbol 
          symbol: class Distance 
          location: class com.pants.examples.hello.greet.Greeting 
          Distance proto = Distance.getDefaultInstance(); 
          ^
         /Users/zundel/Src/pants/examples/src/java/com/pants/examples/hello/greet/Greeting.java:37: error: cannot find symbol 
          symbol: variable Distance 
          location: class com.pants.examples.hello.greet.Greeting 
          Distance proto = Distance.getDefaultInstance(); 
              ^
         Reading existing dependency file at /Users/zundel/Src/pants/.pants.d/compile/jvm/java/jmake-depfiles/global_depfile 
         Writing class dependency file to /Users/zundel/Src/pants/.pants.d/compile/jvm/java/jmake-depfiles/global_depfile 
         Writing project database... Done. 

FAILURE: compilation error 


       Waiting for background workers to finish. 
       FAILURE 

回答

2

首先要注意的一點是,試運行綠色在IntelliJ IDEA的項目所產生的事實:

$ ./pants idea \ 
    examples/tests/java/com/pants/examples/hello/greet:: \ 
    examples/tests/java/com/pants/examples/useproto:: 

是您在命令行上選擇的目標的結果,而不是事實你在IDEA中運行測試。

例如,如果運行從像這樣在命令行測試時,它們也通過:

$ ./pants test \ 
    examples/tests/java/com/pants/examples/hello/greet:: \ 
    examples/tests/java/com/pants/examples/useproto::` 

如你所指出的,根本原因是褲子是讓examples/tests/java/com/pants/examples/hello/greet目標來引用代碼它具有不宣佈依賴於。簡而言之,這是今天褲子ideatest目標中的一個缺陷。

  1. idea錯誤

    的想法目前的目標爲產生在命令行上指定的所有目標的一個模塊,這使得彼此可見的IDEA的編譯方案的目的,所有目標。相反,這個想法目標應該確實生成一個每個目標模塊。您可以嘗試使用IDEA Pants Support插件作爲./pants idea命令行目標的替代方案。

  2. test錯誤

    這確實是其中test隱含運行compile目標的錯誤。就目前而言,jvm編譯的褲子在概念上是批處理的。如果像遞歸目標遍歷那樣遞交很多目標,則它會將目標的結果傳遞閉包視爲用於類路徑和源路徑目的的一個編譯單元。現在這是一個白色的謊言,在某些情況下褲子被迫分解成幾個塊,在這種情況下,一些未聲明的依賴關係的目標也可能失敗。

    現在有工作正在進行中,讓褲子從概念批量轉移到真正的每個目標單獨編譯。一旦這項工作完成,默認情況下或通過配置repo的pants.ini,上面的globbed測試命令和單個目標測試命令都將在編譯階段失敗。

+0

謝謝約翰。我注意到在爲IntelliJ使用Pants Support插件時,它會爲每個目標創建單獨的模塊,以強制Pants BUILD文件中聲明的依賴關係。 – ericzundel 2015-04-03 20:20:41

相關問題