1

My project started with a single build.gradle (no multi-project). The project has src/test/java and src/test/kotlin folders. So far, I have applied the configuration for both projects.

Main problem is the incompatibility with JDK 9 for java submodule and JDK 8 for kotlin submodule. With this error message

Could not target platform: 'Java SE 9' using tool chain: 'JDK 8 (1.8)'.

I want to apply:

  • only to src/test/java a specific config (sourceCompatibility = 1.9)
  • same to src/test/kotlin this config (kotlinOptions.jvmTarget = "1.8")

How can I split both folders (java and kotlin) into submodules without moving files ? The folders don't have to be split as submodules. I only want to apply different compilations options.

The project build.gradle is there

Raymond Chenon
  • 11,482
  • 15
  • 77
  • 110

2 Answers2

0

Use sourceSets

sourceSets {

                test {
                    kotlin {
                        srcDirs = ["src/test/kotlin"]
                    }
                    java {
                        srcDirs = ["src/test/java"]
                    }
                }
            }
Chayne P. S.
  • 1,558
  • 12
  • 17
  • can you be more precise how to apply a specific JDK version to them? – Raymond Chenon Sep 11 '20 at 09:44
  • @RaymondChenon Can you show me the result of "gradle build -i"? I cannot replicate the error by only have build.gradle file. – Chayne P. S. Sep 11 '20 at 12:45
  • The gradle file is linked above https://github.com/raychenon/algorithms/blob/master/build.gradle – Raymond Chenon Sep 11 '20 at 16:45
  • @RaymondChenon Thing is I can run "gradle build" on my empty folder and it returned no error. So, only build.gradle file is not enough for me to replicate your problem. – Chayne P. S. Sep 11 '20 at 16:49
  • clone the project and use `./gradlew build` at the root folder. Gradlew is the wrapper which uses the gradle version in the project. Whereas `gradle` command uses the version on your system. – Raymond Chenon Sep 11 '20 at 16:52
  • @RaymondChenon I use OsX that have gradle-or-gradlew that can detect the gradlew in working dir and use it instead. Your build.gradle also has no wrapper section to indicate gradle version anyway. Look, I want to help you but I have no time to investigate the whole of your project. Just give me the result of "gradlew build -i" which will indicate what task throw the error. – Chayne P. S. Sep 11 '20 at 17:05
  • `> Task :compileJava FAILED Caching disabled for task ':compileJava' because: Build cache is disabled Task ':compileJava' is not up-to-date because: Task has failed previously. The input changes require a full rebuild for incremental task ':compileJava'. :compileJava (Thread[Execution worker for ':',5,main]) completed. Took 0.009 secs. FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':compileJava'. > Could not target platform: 'Java SE 9' using tool chain: 'JDK 8 (1.8)'.` – Raymond Chenon Sep 11 '20 at 17:18
  • @RaymondChenon What is your JDK version? look like you use JDK 8 but want it to produce 9 ? – Chayne P. S. Sep 11 '20 at 17:52
  • I use JDK version 1.12 , on IntelliJ the project level is JDK 9. `src/main/kotlin` only supports up to JDK 8. But the `src/main/java` uses features in JDK 9 . It is described in the original post. – Raymond Chenon Sep 11 '20 at 19:49
0

I found an answer how to run in IntelliJ, https://stackoverflow.com/a/58796344/311420

Basically, I was trying to use gradle configuration to run. But the tests fail in Intellij but not in gradle. Now I run the tests with IntelliJ configurations not gradle.

It is half satisfactory answer.

You can see how my tests in Circle CI and Travis CI

Raymond Chenon
  • 11,482
  • 15
  • 77
  • 110