Polyglot support: Configure Java to find compiled Clojure classes. Is it possible?

Hello. I have a polyglot project that contains both Java and Clojure. My Clojure files contain gen class directives that correctly compile inside of Maven, and my java classes can find the clojure classes successfully while running junit tests inside of the Maven build. However, when editting a java source file and declaring/calling to a compiled clojure class from a java source file within Intellij, the references to the clojure classes are not recognized. This seems to make sense, as I wouldn't really expect the java builder to look inside of a .clj file to be able to determine the class references. But as mentioned, I am able to compile and run unit test cases successfully through a Maven build whereby compiled java and clojure classes co-exist and java calls to clojure successfully. The missing piece seems to be polyglot support between .java and .clj files within the Intellij editor.Anybody have experience with this type of set up (java calling and finding clojure gen classes within the editor)? Does polyglot support for java calling/recognizing clojure within Intellij exist, or is it just not there yet? (I have the La Clojure plugin installed with Intellij 12.1.6).Thanks very much in advance for any insights.
2 comments

La Clojure currently only supports classes generated with :gen-class keyword in the ns declaration, which is at the very beginning of the file. For other cases, there is this request: http://youtrack.jetbrains.com/issue/CLJ-229

0

It is possible. See this example:

 

build.gradle (polyglot, Java Spring Boot & Clojure)

```



buildscript {
ext {
springBootVersion = '1.5.8.RELEASE'
}
repositories {
jcenter()
maven { url 'http://clojars.org/repo' }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
classpath "com.netflix.nebula:nebula-clojure-plugin:4.4.0"
}
}


plugins {
id "nebula.clojure" version "4.4.0"
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'application'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'


group 'com.demo'
def artifactName = 'demo-service'
version = latestRepoTag()


static def latestRepoTag() {
def cmd ="git describe --abbrev=0"
def proc = cmd.execute();
return proc.text.trim();
}

sourceCompatibility = 1.8
targetCompatibility = 1.8


ext['spring-restdocs.version'] = '1.2.1.RELEASE'
ext {
springCloudVersion = 'Dalston.SR4'
}

compileJava {
classpath = project.files(
project.compileClojure.outputs,
classpath
)
}

compileClojure {
jvmOptions {
jvmArgs '-Djava.awt.headless=true'
}
}

repositories {
jcenter()
maven { url 'http://clojars.org/repo' }
}

jar {
baseName = "${artifactName}"
version = latestRepoTag()
}


clojure.aotCompile = true

configurations{
dev
}


dependencyManagement {
imports {
mavenBom 'org.springframework.cloud:spring-cloud-dependencies:Dalston.SR3'
}
}


dependencies {

compile 'org.clojure:clojure:1.6.0'

compile('com.google.guava:guava:19.0')
compile("commons-io:commons-io:2.5")
compile "org.apache.pdfbox:pdfbox:2.0.0-RC3"
compile("org.apache.commons:commons-lang3:3.0")
compile("org.springframework.boot:spring-boot-starter-actuator")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.boot:spring-boot-starter-jdbc")
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.cloud:spring-cloud-starter-eureka")

compileOnly("org.projectlombok:lombok:1.16.6")

runtime('com.h2database:h2:1.4.190')
runtime("com.ingres.jdbc:iijdbc:10.0-4.0.5")
runtime('org.apache.commons:commons-dbcp2:2.1.1')
runtime('org.postgresql:postgresql:9.4.1209')

dev("org.springframework.boot:spring-boot-devtools")

testCompile('com.jayway.jsonpath:json-path')
testCompile('com.jayway.jsonpath:json-path-assert:2.2.0')
testCompile('com.google.code.gson:gson:2.8.1')
testCompile("org.springframework.boot:spring-boot-starter-test")
testCompile("org.springframework.restdocs:spring-restdocs-mockmvc:1.2.1.RELEASE")

}

task wrapper(type: Wrapper) {
gradleVersion = '4.1'
}

bootRun {
classpath = sourceSets.main.runtimeClasspath + configurations.dev
systemProperties = System.properties
jvmArgs = ["-client", "-Dsun.net.inetaddr.ttl=60", "-Djava.security.egd=file:/dev/./urandom"]
environment = [
'spring_profiles_active': 'beta,fast_discovery'
]
}


```
0

Please sign in to leave a comment.