【问题标题】:error: generics are not supported in -source 1.3 when compiling Java code with Kotlin错误:使用 Kotlin 编译 Java 代码时,-source 1.3 不支持泛型
【发布时间】:2016-02-11 12:46:02
【问题描述】:

我正在使用 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 编译放在&lt;phase&gt;process-sources&lt;/phase&gt; 而不是&lt;phase&gt;compile&lt;/phase&gt;。我(可能是错误的?)假设 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

为什么会这样?

【问题讨论】:

标签: java maven jenkins kotlin


【解决方案1】:

我注意到在这个特定的 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>

【讨论】:

    猜你喜欢
    • 2010-09-11
    • 1970-01-01
    • 1970-01-01
    • 2012-04-21
    • 1970-01-01
    • 1970-01-01
    • 2011-04-18
    • 2020-02-08
    • 1970-01-01
    相关资源
    最近更新 更多