3

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?

Community
  • 1
  • 1
Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
  • What is the difference with those questions: http://stackoverflow.com/q/6513479/1743880, or http://stackoverflow.com/q/7597950/1743880, or http://stackoverflow.com/q/16662830/1743880? – Tunaki Feb 11 '16 at 12:55
  • 1
    @Tunaki: No Kotlin. Specifically, I (wrongly) assumed that the Kotlin compiler would also compile Java classes for me. – Lukas Eder Feb 11 '16 at 13:03
  • 2
    @LukasEder Kotlin only uses the Java classes to generate stubs for Kotlin to compile against, then Kotlin is compiled before Java, later SOMETHING ELSE compiles Java. – Jayson Minard Feb 12 '16 at 03:21

1 Answers1

5

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>
Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509