我正在使用 Maven 和 kotlin-maven-plugin
编译代码。
<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>
target/generated-sources/jooq-h2
目录包含 Java 源文件。我正在关注 Kotlin manual及其他people's recommendation通过将 Kotlin 编译器放入 <phase>process-sources</phase>
而不是 <phase>compile</phase>
.我(可能是错误的?)假设 Kotlin 编译器也负责为我编译这些 Java 文件。
但是,在某些服务器上(例如 Jenkins CI),我得到了奇怪的编译错误消息,例如:
[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
这是为什么?
最佳答案
我注意到在这个特定的 Kotlin 项目中,没有指定 Java 编译器,特别是 Java 版本。这导致选择了一些机器默认值,我的本地机器是 Java 1.8,但 Jenkins CI 服务器上是 Java 1.3。添加对 maven-compiler-plugin
的显式引用为我解决了这个问题:
<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>
关于java - 使用Kotlin编译Java代码时报错: generics are not supported in -source 1. 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35339749/