简体   繁体   English

我如何编译一个多模块Maven项目,其中一个模块同时具有clojure和Java代码

[英]How can I compile a multi-module maven project, where a module have both clojure and java code

I've a multi module maven project, where one of the modules have both java and clojure code, clojure code requires a pojo from java source and another class in java source require clojure compiled code (I've added :gen-class and project compiles well even though it gave an error initially as failed to see java class I when clojure-maven-plugin and compiles do a clojure:compile and compile). 我有一个多模块Maven项目,其中一个模块同时具有Java和Clojure代码,Clojure代码需要来自Java源的pojo,而Java源中的另一个类需要Clojure编译后的代码(我已经添加了:gen-class和project即使最初给出了一个错误,编译也很好,因为当clojure-maven-plugin和compiles执行clojure:compile和compile时,无法看到Java类I。 But this is not working from the outer pom where it manages the multi modules. 但这在管理多个模块的外部pom中不起作用。 Appreciate any help on finding a solution 感谢您寻找解决方案的帮助

As one of the comments said, clojure-maven-plugin cannot handle circular dependencies between Java and Clojure code in the same module. 正如评论之一所说,clojure-maven-plugin无法处理同一模块中Java和Clojure代码之间的循环依赖关系。 Java code is compiled before Clojure code. Java代码在Clojure代码之前进行编译。

But you could restructure the code to eliminate circular dependencies. 但是您可以重组代码以消除循环依赖。 Split the Java + Clojure project (maven module) into three: 将Java + Clojure项目(Maven模块)分成三个部分:

  • Base Java module 基本Java模块
  • Clojure module Clojure模块
  • 2nd Java module 第二个Java模块

The Base Java module would at least include the POJO that the Clojure module needs and possibly other common things. 基本Java模块将至少包括Clojure模块所需的POJO以及其他可能的常见事物。 The Clojure module would contain all the Clojure code, and the 2nd Java module would contain the part of Java code that requires a class that is generated by the Clojure compiler. Clojure模块将包含所有Clojure代码,第二Java模块将包含Java代码的一部分,该部分需要由Clojure编译器生成的类。 Only the Clojure modules requires the clojure-maven-plugin. 仅Clojure模块需要clojure-maven-plugin。

You could then setup dependencies between those modules, such that: 然后,您可以在这些模块之间设置依赖性,例如:

  • Clojure module depends on the Base Java artefact Clojure模块取决于Base Java工件
  • 2nd Java module depends on the Base Java and the Clojure artefacts 第二个Java模块取决于基础Java和Clojure工件

As long as the AOT compilation is setup properly in the Clojure module, everything should now compile. 只要在Clojure模块中正确设置了AOT编译,所有内容现在都应该编译了。 I believe clojure-maven-plugin AOT-compiles all namespaces by default. 我相信clojure-maven-plugin AOT默认会编译所有名称空间。 Without the AOT compilation, (gen-class) does nothing. 没有AOT编译, (gen-class)什么也做不了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM