2012-10-15 122 views
1

我試圖建立我的項目,有一些Java的源和Clojure的源代碼,在目錄結構如下所示:重新排序編譯任務gradle產出的構建任務

src 
`-- main 
    |-- clojure 
    | `-- appc 
    |  `-- core.clj 
    `-- java 
     `-- appj 
      `-- AppStarter.java 

我已經裝了javaclojureapplication插件在我的gradle構建文件中。 Clojure插件是從https://bitbucket.org/kotarak/clojuresque/overview,版本1.5.2

在這裏,clojure代碼core.clj具有使用用java編寫的類的代碼。但是java源代碼中沒有什麼依賴clojure代碼。

現在,當我做gradle tasks --all,我看到

... 
classes - Assembles the main classes. 
    compileClojure - Compile the main Clojure source. 
    compileJava - Compiles the main Java source. 
    processResources - Processes the main resources. 
... 

因此,build任務將首先編譯我的Clojure源,然後Java源代碼。這顯然不起作用,因爲clojure代碼依賴於java部分。所以我需要compileJava發生在compileClojure之前。

更改應用clojurejava插件的順序沒有任何影響。

由於clojure插件是新的,我試用了groovyscala插件。在每種情況下我都得到了以下結果。

... 
classes - Assembles the main classes. 
    compileGroovy - Compile the main Groovy source. 
    compileJava - Compiles the main Java source. 
    processResources - Processes the main resources. 
... 

... 
classes - Assembles the main classes. 
    compileJava - Compiles the main Java source. 
    compileScala - Compile the main Scala source. 
    processResources - Processes the main resources. 
... 

我想應該重新安排這些正確的方法嗎?我無法找到在文檔中(儘管他們是真的好!)。有什麼辦法可以告訴gradle首先編譯我的java源代碼,然後編譯clojure源代碼?

回答

3

獲得訂單權限與compileClojure.dependsOn(compileJava)一樣簡單。另一個問題是如果Java類正確放置在Clojure編譯器的類路徑上。

PS:gradle tasks輸出中的任務順序沒有說明任務的執行順序。任務執行順序完全由任務依賴性決定。

+0

你說得對!添加該行後,gradle按照我希望的方式運行,但'tasks - all'中的順序沒有變化。我正在嘗試'build.dependsOn compileJava'。好吧。非常感謝,它現在有效。 –

+0

java編譯器的輸出應正確放置在clojure編譯任務的類路徑中。我不依賴java編譯,因爲先驗不清楚哪一種方法是「正確的」。同樣,Java源代碼也可以依賴clojure部分生成的類。所以用戶必須明確指定他想要的。 – kotarak

相關問題