# Mixed Scala Java Project - Set Compilation Order to JavaThenScala

**URL:** https://discuss.gradle.org/t/mixed-scala-java-project-set-compilation-order-to-javathenscala/5869
**Category:** Old Forum Archive
**Created:** [November 11, 2014, 10:54am UTC](https://discuss.gradle.org/t/mixed-scala-java-project-set-compilation-order-to-javathenscala/5869 "2014-11-11T10:54:00Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![david\_koch444](https://avatars.discourse-cdn.com/v4/letter/d/e0b2c6/32.png) [@david\_koch444](https://discuss.gradle.org/u/david_koch444)
#### Post date: [November 11, 2014, 10:54am UTC](https://discuss.gradle.org/t/mixed-scala-java-project-set-compilation-order-to-javathenscala/5869/1 "2014-11-11T10:54:00Z")

</div>

Due to a issue [SI-5333](https://issues.scala-lang.org/browse/SI-5333) in scalac I need to compile all java classes before all scala classes.

I’ve tried it the dependency way:

compileScala.dependsOn(compileJava)

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

---

<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: [November 11, 2014, 12:09pm UTC](https://discuss.gradle.org/t/mixed-scala-java-project-set-compilation-order-to-javathenscala/5869/2 "2014-11-11T12:09:00Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![david\_koch444](https://avatars.discourse-cdn.com/v4/letter/d/e0b2c6/32.png) [@david\_koch444](https://discuss.gradle.org/u/david_koch444)
#### Post date: [November 11, 2014, 12:39pm UTC](https://discuss.gradle.org/t/mixed-scala-java-project-set-compilation-order-to-javathenscala/5869/3 "2014-11-11T12:39:00Z")

</div>

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.

Java:

class Constants{

public final static String CONST = “const value”;

}

Scala:

class Client{

@Qualifier(Constants.CONST)

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](https://issues.scala-lang.org/browse/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

---

<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: [November 11, 2014, 12:51pm UTC](https://discuss.gradle.org/t/mixed-scala-java-project-set-compilation-order-to-javathenscala/5869/4 "2014-11-11T12:51:00Z")

</div>

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.
