简体   繁体   中英

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). But this is not working from the outer pom where it manages the multi modules. 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. Java code is compiled before Clojure code.

But you could restructure the code to eliminate circular dependencies. Split the Java + Clojure project (maven module) into three:

  • Base Java module
  • Clojure module
  • 2nd Java module

The Base Java module would at least include the POJO that the Clojure module needs and possibly other common things. 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. Only the Clojure modules requires the clojure-maven-plugin.

You could then setup dependencies between those modules, such that:

  • Clojure module depends on the Base Java artefact
  • 2nd Java module depends on the Base Java and the Clojure artefacts

As long as the AOT compilation is setup properly in the Clojure module, everything should now compile. I believe clojure-maven-plugin AOT-compiles all namespaces by default. Without the AOT compilation, (gen-class) does nothing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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