Can I have different sourceCompatibility for "main" and "test" classes?

We have some projects that have to run in old application server contains, and thus need to be built with sourceCompatibility=1.6. However, the test code does not have these limitations, and there are stuff in 1.7 that we would like to use there.

We currently use project.sourceCompatibility=“1.6” to specifiy the source compatibility.

-> Is there a way to set up different sourceCompatibility for classes in the “test” and “main” sourceSets?

You can override it on the test compile task.

compileTestJava {
  sourceCompatibility = "1.7"
1 Like

Super. Thanks!