# Project mixing scala and groovy does not compile with gradle 4.0

**URL:** <https://discuss.gradle.org/t/project-mixing-scala-and-groovy-does-not-compile-with-gradle-4-0/22973>\
**Category:** Help/Discuss\
**Created:** [June 15, 2017, 2:26pm UTC](https://discuss.gradle.org/t/project-mixing-scala-and-groovy-does-not-compile-with-gradle-4-0/22973 "2017-06-15T14:26:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![feli74](https://avatars.discourse-cdn.com/v4/letter/f/22d042/32.png) [@feli74](https://discuss.gradle.org/u/feli74)\
**Post date:** [June 15, 2017, 2:26pm UTC](https://discuss.gradle.org/t/project-mixing-scala-and-groovy-does-not-compile-with-gradle-4-0/22973/1 "2017-06-15T14:26:04Z")

</div>

Hi,

I have a scala project that uses a tiny bit of groovy source code (a single class to be precisely). I am applying the _groovy_ plugin; and the sources are locates in _src/main/scala_ and _src/main/groovy_. This used to work fine, however when I gave 4.0 a shot I got this error:

```
> Task :XXX:YYY:compileScala
Pruning sources from previous analysis, due to incompatible CompileSetup.
/path/to/some/ScalaSourceFile.scala:162: not found: type SomeClassWrittenInGroovy

```

where SomeClassWrittenInGroovy is located under src/main/groovy

–debug reveals that the -classpath passed to the scala compiler doesn’t include build/classes/groovy/main:

```
16:13:41.369 [DEBUG] [org.gradle.api.internal.tasks.scala.ZincScalaCompiler] Calling Scala compiler with arguments (CompilerInterface):
	-deprecation
	-unchecked
	-bootclasspath
	/usr/lib/jvm/java-8-oracle/jre/lib/resources.jar:/usr/lib/jvm/java-8-oracle/jre/lib/rt.jar:/usr/lib/jvm/java-8-oracle/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jsse.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jce.jar:/usr/lib/jvm/java-8-oracle/jre/lib/charsets.jar:/usr/lib/jvm/java-8-oracle/jre/lib/jfr.jar:/usr/lib/jvm/java-8-oracle/jre/classes:/home/felix/.gradle/caches/modules-2/files-2.1/org.scala-lang/scala-library/2.12.2/fe9780170207ebdabd4ac5bb335c82bd0aead480/scala-library-2.12.2.jar
	-classpath
	/MY_PROJECT_HOME/XX/YY/build/classes/scala/main:<LONG_LIST_OF_DEPENDENCIES>:/MY_PROJECT_HOME/XX/YY/build/classes/java/main:/MY_PROJECT_HOME/XX/YY/build/classes/scala/main

```

Now how can I make the scala compiler to include `/MY_PROJECT_HOME/XX/YY/build/classes/groovy/main` into -classpath ?

---

<div class="post-metadata">

**Author:** ![feli74](https://avatars.discourse-cdn.com/v4/letter/f/22d042/32.png) [@feli74](https://discuss.gradle.org/u/feli74)\
**Post date:** [June 15, 2017, 2:50pm UTC](https://discuss.gradle.org/t/project-mixing-scala-and-groovy-does-not-compile-with-gradle-4-0/22973/2 "2017-06-15T14:50:12Z")

</div>

So I followed the suggestion in the release notes and added this to my build file:

`sourceSets.main.output.classesDir = new File(buildDir, "classes/main")`

which helps. It turns out that the message `Pruning sources from previous analysis, due to incompatible CompileSetup.` was not related to the issue.

Anyway, this is just a workaround, so I would still like to understand how I can control the class path of the scala compiler task or how to enable joint compilation of scala and groovy sources. Anyone?

---

<div class="post-metadata">

**Author:** ![sterling](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/sterling/32/5395_2.png) [@sterling](https://discuss.gradle.org/u/sterling)\
**Post date:** [June 15, 2017, 5:32pm UTC](https://discuss.gradle.org/t/project-mixing-scala-and-groovy-does-not-compile-with-gradle-4-0/22973/3 "2017-06-15T17:32:56Z")

</div>

Did you have any other configuration in your build before?  
e.g., something like

`compileScala.dependsOn compileGroovy`

---

<div class="post-metadata">

**Author:** ![feli74](https://avatars.discourse-cdn.com/v4/letter/f/22d042/32.png) [@feli74](https://discuss.gradle.org/u/feli74)\
**Post date:** [June 15, 2017, 9:21pm UTC](https://discuss.gradle.org/t/project-mixing-scala-and-groovy-does-not-compile-with-gradle-4-0/22973/4 "2017-06-15T21:21:38Z")

</div>

No, just the `apply plugin:` statements.  
So I gave it a shot but the result is the same. The groovy classes dir is still not passed with `-classpath`.

---

<div class="post-metadata">

**Author:** ![sterling](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/sterling/32/5395_2.png) [@sterling](https://discuss.gradle.org/u/sterling)\
**Post date:** [June 15, 2017, 9:52pm UTC](https://discuss.gradle.org/t/project-mixing-scala-and-groovy-does-not-compile-with-gradle-4-0/22973/5 "2017-06-15T21:52:45Z")

</div>

Sorry, I didn’t mean to imply that would fix it.

This used to work because all compilation tasks shared the same output directory, so depending on the order that the compilation tasks would run, you could depend on classes from earlier compilation tasks.

Since there was no relationship between `compileGroovy` and `compileScala`, you were getting lucky that Groovy compilation would happen before Scala compilation.

I’ve opened an issue for this: [https://github.com/gradle/gradle/issues/2312](https://github.com/gradle/gradle/issues/2312)

As a different workaround, you could do this:

```gradle
compileScala {
    classpath = classpath.plus(files(compileGroovy.destinationDir))
    dependsOn compileGroovy
}

```

This explicitly adds the Groovy compilation output directory to the classpath for Scala.
