I have a maven project that contains two subprojects, one contains Clojure source, and the second contains Java source.
This is the top level POM file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>maven-clojure-test-2</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>clojure</module>
<module>java</module>
</modules>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
The Clojure project is set up to compile using clojure-maven-plugin
, with the following POM file:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.example</groupId>
<artifactId>maven-clojure-test-2</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>clojure</artifactId>
<packaging>clojure</packaging>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.theoryinpractise</groupId>
<artifactId>clojure-maven-plugin</artifactId>
<version>1.8.3</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.clojure</groupId>
<artifactId>clojure</artifactId>
<version>1.11.2</version>
</dependency>
</dependencies>
</project>
This project contains a single clojure source file, shown here:
(ns clojuretest.test
(:gen-class
:methods
[[hello [] void]]))
(defn -hello [this] (println "running in clojure"))
The Java project is using IntelliJ’s default settings, except that it has a dependency to the clojure project:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.example</groupId>
<artifactId>maven-clojure-test-2</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>java</artifactId>
<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.example</groupId>
<artifactId>clojure</artifactId>
<version>${project.parent.version}</version>
</dependency>
</dependencies>
</project>
This project also has a single source file:
package javatest;
public class Main
{
public static void main(String[] args) {
System.out.println ("Java");
new clojuretest.test().hello();
}
}
When I compile this with Maven, everything works fine. The Java main function is able to be run, and the expected output is produced:
Java
running in clojure
However, the IntelliJ’s java editor highlights new clojuretest.test().hello()
as an error, and says that clojuretest
is undefined. I presume it’s searching for Java source files, not looking at the compiled .class
files, to identify what is and is not a valid dependency.
How do I get it to recognize the classes built in a local dependency that aren’t implemented in Java?
Things I’ve tried:
- Enabling the “Delegate IDE build/run actions to Maven” checkbox
- Invalidating caches
- Adding the generated jar file in the clojure module as a library to the java module (by using right click -> add as library); this works, but isn’t ideal because I will need to remove it and add it back in every time I increase the module’s version number.
Really, I just need to find a way of telling IDEA to just use the contents of the module’s jar file rather than trying to find source files in it.
Any ideas?