java - Kotlin + Java 9 模块(使用 Java 11)+ maven
问题描述
我用 Java 和 Kotlin 代码创建了一个简单的项目,我正在尝试将它编译为 Java 9 模块。这是我的 pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>simple-kotlin-module</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<kotlin.version>1.3.72</kotlin.version>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<classifier>modular</classifier> <!-- FIXME: do we need this? -->
<version>${kotlin.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<compilerVersion>${java.version}</compilerVersion>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<source>${java.version}</source>
<target>${java.version}</target>
<verbose>true</verbose>
</configuration>
<executions>
<!-- Replacing default-compile as it is treated specially by maven -->
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<!-- Replacing default-testCompile as it is treated specially by maven -->
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>java-compile</id>
<phase>compile</phase>
<goals> <goal>compile</goal> </goals>
</execution>
<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<goals> <goal>testCompile</goal> </goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
<execution>
<id>compile</id>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<jvmTarget>11</jvmTarget>
<args>
<arg>-Xjvm-default=enable</arg>
</args>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>toolchain</goal>
</goals>
</execution>
</executions>
<configuration>
<toolchains>
<jdk>
<version>[${java.version},12)</version>
</jdk>
</toolchains>
</configuration>
</plugin>
</plugins>
</build>
</project>
这是我的module-info.java:
module simple.kotlin.module {
requires kotlin.stdlib;
}
我没有展示我的代码文件——它们尽可能简单,java 一个包含 main 方法并依赖于 kotlin 一个。
我遇到了一个例外:
[ERROR] Failed to execute goal org.jetbrains.kotlin:kotlin-maven-plugin:1.3.72:compile (compile) on project simple-kotlin-module: Compilation failure
[ERROR] Module java.base cannot be found in the module graph
我使用的是 maven 3.6.3,使用 Java 1.8.0_211 运行,所以我必须使用 maven-toolchain-plugin 来选择 java 11。
解决方案
推荐阅读
- python - 我正在尝试使用 POST 请求上传文件。文件未上传
- javascript - 我想在页面下方的时间选择器下拉列表中
- ios - UICollectionViewCompositionalLayout 以编程方式设置 section.orthogonalScrollingBehavior 页面?
- python - 刮板返回空结果
- python - 如何使用 python/pandas 汇总与来自不同数据框的类别相关的值?
- python - 使用 Python SSHTunnelForwarder 的“NoneType”错误
- acumatica - 如何在 Acumatica 中运行确认装运操作时更新自定义字段值
- vue.js - v-on:click 永远不会触发 Nuxt 组件中的按钮,因为中间件
- emulation - 需要不良的编码习惯
- javascript - 如何解决:EEXIST:文件已存在,在 React Native 中生成 apk 后 mkdir 'C:\Users\OKR\Desktop\MeetUp' 失败?