Compiling Scala before / alongside Java with Gradle

crizCraig picture crizCraig · Apr 24, 2014 · Viewed 7.4k times · Source

The default scala plugin task flow compiles Java before Scala so importing Scala sources within Java causes "error: cannot find symbol". scala task flow

Answer

crizCraig picture crizCraig · Apr 24, 2014

I found the following sourceSet config to fix the problem:

sourceSets {
    main {
        scala {
            srcDirs = ['src/main/scala', 'src/main/java']
        }
        java {
            srcDirs = []
        }
}

This because the scala source set can include both java and scala sources.