我正在尝试在如下目录结构中构建具有一些 java 源代码和 clojure 源代码的项目:
src
`-- main
|-- clojure
| `-- appc
| `-- core.clj
`-- java
`-- appj
`-- AppStarter.java
我已经在我的 gradle 构建文件中加载了 java
、clojure
和 application
插件。 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
之前发生。
更改 clojure
和 java
插件的应用顺序没有任何效果。
由于 clojure 插件是新的,我尝试了 groovy
和 scala
插件。我在每种情况下都得到了以下信息。
...
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 源代码?
最佳答案
获得正确的顺序就像 compileClojure.dependsOn(compileJava)
一样简单。另一个问题是 Java 类是否正确放置在 Clojure 编译器的类路径中。
PS:gradle tasks
输出中的任务顺序没有说明任务执行的顺序。任务执行顺序完全由任务依赖关系决定。
关于java - 在 gradle 的构建任务中重新排序编译任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12899185/