I'm using Maven and the kotlin-maven-plugin to compile code.
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<source>src/main/kotlin</source>
<source>src/main/resources</source>
<source>target/generated-sources/jooq-h2</source>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<phase>process-test-sources</phase>
<goals>
<goal>test-compile</goal>
</goals>
<configuration>
<sourceDirs>
<source>src/test/kotlin</source>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>
The target/generated-sources/jooq-h2 directory contains Java source files. I'm following the Kotlin manual and other people's recommendation by putting the Kotlin complation in <phase>process-sources</phase> rather than <phase>compile</phase>. I'm (probably wrongly?) assuming that the Kotlin compiler also takes care of compiling those Java files for me.
However, on some servers (e.g. Jenkins CI), I got strange compilation error messages, such as:
[ERROR] /var/lib/jenkins/jobs/jooq-build/workspace/jOOQ-examples/jOOQ-kotlin-example/target/generated-sources/jooq-h2/org/jooq/example/db/h2/tables/Author.java:[35,37]
error: generics are not supported in -source 1.3
Why is that?
I've noticed that in this particular Kotlin project, the Java compiler and specifically the Java version were not specified. This resulted in some machine default having been chosen, which is Java 1.8 for my local machine, but Java 1.3 on the Jenkins CI server. Adding an explicit reference to the maven-compiler-plugin solved the issue for me:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With