【问题标题】:Reorder compile tasks in gradle's build task在 gradle 的构建任务中重新排序编译任务
【发布时间】:2012-10-15 15:43:42
【问题描述】:

我正在尝试在如下目录结构中构建包含一些 java 源代码和 clojure 源代码的项目:

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

我已经在我的 gradle 构建文件中加载了 javaclojureapplication 插件。 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 部分。所以我需要compileJavacompileClojure 之前发生。

更改应用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 源码 build,然后再编译 clojure 源码?

【问题讨论】:

    标签: java groovy clojure build-process gradle


    【解决方案1】:

    获得正确的订单就像compileClojure.dependsOn(compileJava) 一样简单。另一个问题是 Java 类是否正确放置在 Clojure 编译器的类路径中。

    PS:gradle tasks 输出中的任务顺序没有说明任务执行的顺序。任务执行顺序完全由任务依赖决定。

    【讨论】:

    • 你是对的!添加该行后,gradle 会按照我想要的方式运行,但tasks --all 中的顺序没有改变。我正在尝试build.dependsOn compileJava。那好吧。非常感谢,现在可以使用了。
    • java 编译器的输出应该正确放置在 clojure 编译任务的类路径中。我不依赖 java 编译,因为先验并不清楚哪种方式是“正确的”方式。同样,java 源代码可能依赖于 clojure 部分生成的类。所以用户必须明确指定他想要什么。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-02
    • 2011-06-03
    • 2015-03-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多