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

**URL:** https://discuss.gradle.org/t/is-it-possible-to-have-java-groovy-scala-polyglot-project-and-have-it-compiled-via-gradle/7210
**Category:** Old Forum Archive
**Created:** [May 10, 2013, 9:12pm UTC](https://discuss.gradle.org/t/is-it-possible-to-have-java-groovy-scala-polyglot-project-and-have-it-compiled-via-gradle/7210 "2013-05-10T21:12:00Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Ravi\_Hasija](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/ravi_hasija/32/1169_2.png) [@Ravi\_Hasija](https://discuss.gradle.org/u/Ravi_Hasija)
#### Post date: [May 10, 2013, 9:12pm UTC](https://discuss.gradle.org/t/is-it-possible-to-have-java-groovy-scala-polyglot-project-and-have-it-compiled-via-gradle/7210/1 "2013-05-10T21:12:00Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)
#### Post date: [May 11, 2013, 1:14am UTC](https://discuss.gradle.org/t/is-it-possible-to-have-java-groovy-scala-polyglot-project-and-have-it-compiled-via-gradle/7210/2 "2013-05-11T01:14:00Z")

</div>

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).

---

<div class="post-metadata">

### Author: ![Ravi\_Hasija](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/ravi_hasija/32/1169_2.png) [@Ravi\_Hasija](https://discuss.gradle.org/u/Ravi_Hasija)
#### Post date: [May 11, 2013, 4:03am UTC](https://discuss.gradle.org/t/is-it-possible-to-have-java-groovy-scala-polyglot-project-and-have-it-compiled-via-gradle/7210/3 "2013-05-11T04:03:00Z")

</div>

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

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!

---

<div class="post-metadata">

### Author: ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)
#### Post date: [May 11, 2013, 12:09pm UTC](https://discuss.gradle.org/t/is-it-possible-to-have-java-groovy-scala-polyglot-project-and-have-it-compiled-via-gradle/7210/4 "2013-05-11T12:09:00Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Dariusz\_Kaczynski](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/dariusz_kaczynski/32/1320_2.png) [@Dariusz\_Kaczynski](https://discuss.gradle.org/u/Dariusz_Kaczynski)
#### Post date: [May 26, 2013, 8:10pm UTC](https://discuss.gradle.org/t/is-it-possible-to-have-java-groovy-scala-polyglot-project-and-have-it-compiled-via-gradle/7210/5 "2013-05-26T20:10:00Z")

</div>

Hi!

I was able to do just that with Maven. Have a look at: [https://bitbucket.org/kaczynskid/java-groovy-scala](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

---

<div class="post-metadata">

### Author: ![Ravi\_Hasija](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/ravi_hasija/32/1169_2.png) [@Ravi\_Hasija](https://discuss.gradle.org/u/Ravi_Hasija)
#### Post date: [May 28, 2013, 2:26am UTC](https://discuss.gradle.org/t/is-it-possible-to-have-java-groovy-scala-polyglot-project-and-have-it-compiled-via-gradle/7210/6 "2013-05-28T02:26:00Z")

</div>

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

---

<div class="post-metadata">

### Author: ![idris](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/idris/32/1509_2.png) [@idris](https://discuss.gradle.org/u/idris)
#### Post date: [October 30, 2014, 2:04pm UTC](https://discuss.gradle.org/t/is-it-possible-to-have-java-groovy-scala-polyglot-project-and-have-it-compiled-via-gradle/7210/7 "2014-10-30T14:04:00Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)
#### Post date: [October 30, 2014, 2:27pm UTC](https://discuss.gradle.org/t/is-it-possible-to-have-java-groovy-scala-polyglot-project-and-have-it-compiled-via-gradle/7210/8 "2014-10-30T14:27:00Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Dariusz\_Kaczynski](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/dariusz_kaczynski/32/1320_2.png) [@Dariusz\_Kaczynski](https://discuss.gradle.org/u/Dariusz_Kaczynski)
#### Post date: [October 30, 2014, 2:39pm UTC](https://discuss.gradle.org/t/is-it-possible-to-have-java-groovy-scala-polyglot-project-and-have-it-compiled-via-gradle/7210/9 "2014-10-30T14:39:00Z")

</div>

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 🙂

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?
