Mixed Scala Java Project - Set Compilation Order to JavaThenScala

Due to a issue SI-5333 in scalac I need to compile all java classes before all scala classes.

I’ve tried it the dependency way:


Unfortunately the scala compiler deletes the output of the java compiler before compiling.

In eclipse its possible to set the compile order to JavaThenScala instead of Mixed. Than everything is fine.

Is there a way to do this in gradle too? Thanks, David

That’s the default - Java classes in ‘src/main/java’ will be compiled before (and separately from) Scala classes in ‘src/main/scala’. The latter should see the former.

My concrete problem boils down to the usage of an final static field declared in a java class which should be used in a java annotation that is applied to a scala method/type.


class Constants{

public final static String CONST = “const value”;



class Client{


def x()={}


the compiler output with gradle is as in the scala issue:

error: annotation argument needs to be a constant; found: Const.CONST

the same problem I have with eclipse if Mixed compile order is set. If I set the compile order for eclipse to JavaThenScala everything is ok (analogously for idea).

With Gradle I always get this error no matter I whether I use the default compiler or zinc with:

scalaCompileOptions.useAnt = false

The issue SI-5333 describes exactly this behavior, where the scala compiler fails in mixed mode to recognize constantness of final static fields declared in java classes.

I’ve observed also the problem, that I could manually compile java first with Gradle. but when I start compileScala all java classes are getting deleted. --david

From what I understand, this is a problem with Scala Java joint compilation. With default settings (e.g. no custom ‘sourceSet’ configuration) and Java code in ‘src/main/java’, there should be no joint compilation, hence I wouldn’t expect this problem to occur. If you can reproduce this in a minimal self-contained example, I’ll have a look.