Is it possible to have Java, Groovy, Scala polyglot project and have it compiled via Gradle?

Suppose we have a project with:

A class ‘src/main/java/JavaA.java’ that refers a class ‘src/main/groovy/GroovyA.groovy’ that refers a scala file ‘src/main/scala/ScalaA.scala’

Is it possible to have a project compile and build via gradle?

Thank you, Ravi H

With a suitable configuration, you can have bidirectional dependencies between Java and Groovy, and/or Java and Scala. You can have unidirectional dependencies between Groovy and Scala (either Groovy->Scala or Scala->Groovy).

Interesting. Is there an example project I can look at? I would much appreciate it! :slight_smile:

I have been able to get bidirectional between Java and Groovy. But to have that together with bidirectional Java and Scala. That would be great. To have Scala work with Groovy would be awesome!!! Please advice!

Thinking about this again, I don’t see a way to get bidirectional Java/Groovy and Java/Scala. At the very least, you’d have to partition your Java code into one part that only interacts with Groovy code, and another one that only interacts with Scala code.

Hi!

I was able to do just that with Maven. Have a look at: https://bitbucket.org/kaczynskid/java-groovy-scala I’m trying Gradle now and will add the build script to the repo if I succeed.

Cheers, Darek

Thank you Darek! I would definitely take a look at it. Unfortunately, going back to Maven is not a choice at work. Besides Gradle does simplify things a lot. I am just hoping that if Maven can do it then hopefully we can find a way to do so in Gradle too! Else Gradle can become an impediment towards polyglot involving more than 2 languages!

Regards, Ravi

Any update on this? Looks like Dariusz has a suitable solution, just needs to be ported to Gradle.

You could do something similar by calling Ant from Gradle like Darek’s Maven build does. Groovy’s stub generator isn’t exposed as a standalone task in Gradle, because it’s known to be flawed and unfixable. For Groovy 2.4, stubless joint generation (which Scala has been doing for a long time) has been promised, which can be totally reliable, but doesn’t allow for Darek’s solution.

The only reliable solution for Java-Groovy-Scala joint compilation that I’m aware of involves enhancing the Groovy joint compiler to be able to parse the Scala language, or the Scala joint compiler to be able to parse the Groovy language. I haven’t heard of anyone working on that.

Exactly as Peter said. My solution will not work in all cases. Only joint compiler parsing all 3 languages at the same time would be the definitive solution. But I don.t feel like writing one :slight_smile:

Maybe some day, some one will come up with pluggable joint compiler for JVM? So that you would be able to plug in any JVM compiler to work side by side any other? But that seems like a long shot. And would it be really useful? Do you see a good use case to even have those 3 languages in one module?