Skip to content

Commit cbbf3ae

Browse files
committed
fix: review suggestions
1 parent acb9cf7 commit cbbf3ae

File tree

1 file changed

+61
-6
lines changed

1 file changed

+61
-6
lines changed

docs/topics/maven.md

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -210,21 +210,73 @@ To control the execution order:
210210
* Disable the Java compiler plugin's default executions.
211211
* Add custom executions to control the compile phases explicitly.
212212

213-
> You can use the special none phase in Maven to disable a default execution.
213+
> You can use the special `none` phase in Maven to disable a default execution.
214214
>
215215
{style="note"}
216216

217-
Here's an example configuration:
217+
You can simplify the configuration of mixed Kotlin/Java compilation using `extensions`.
218+
It allows skipping the Maven compiler plugin configuration:
219+
220+
<tabs group="kotlin-java-maven">
221+
<tab title="With extensions" group-key="with-extensions">
218222

219223
```xml
220224
<build>
221225
<plugins>
222-
<!-- Kotlin compiler plugin -->
226+
<!-- Kotlin compiler plugin configuration -->
223227
<plugin>
224228
<groupId>org.jetbrains.kotlin</groupId>
225229
<artifactId>kotlin-maven-plugin</artifactId>
226230
<version>${kotlin.version}</version>
227231
<extensions>true</extensions>
232+
<executions>
233+
<execution>
234+
<id>default-compile</id>
235+
<phase>compile</phase>
236+
<configuration>
237+
<sourceDirs>
238+
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
239+
<sourceDir>${project.basedir}/src/main/java</sourceDir>
240+
</sourceDirs>
241+
</configuration>
242+
</execution>
243+
<execution>
244+
<id>default-test-compile</id>
245+
<phase>test-compile</phase>
246+
<configuration>
247+
<sourceDirs>
248+
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
249+
<sourceDir>${project.basedir}/src/test/java</sourceDir>
250+
</sourceDirs>
251+
</configuration>
252+
</execution>
253+
</executions>
254+
</plugin>
255+
<!-- No need to configure Maven compiler plugin with extensions -->
256+
</plugins>
257+
</build>
258+
```
259+
260+
If your project previously had a Kotlin-only configuration, you also need to remove the following lines from the `<build>` section:
261+
262+
```xml
263+
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
264+
<testSourceDirectory>${project.basedir}/src/test/kotlin</testSourceDirectory>
265+
```
266+
267+
It ensures that both Kotlin code can reference Java code and vice versa with the `extensions` setup.
268+
269+
</tab>
270+
<tab title="Without extensions" group-key="no-extensions">
271+
272+
```xml
273+
<build>
274+
<plugins>
275+
<!-- Kotlin compiler plugin configuration -->
276+
<plugin>
277+
<groupId>org.jetbrains.kotlin</groupId>
278+
<artifactId>kotlin-maven-plugin</artifactId>
279+
<version>${kotlin.version}</version>
228280
<executions>
229281
<execution>
230282
<id>kotlin-compile</id>
@@ -255,11 +307,11 @@ Here's an example configuration:
255307
</executions>
256308
</plugin>
257309

258-
<!-- Java compiler plugin -->
310+
<!-- Maven compiler plugin configuration -->
259311
<plugin>
260312
<groupId>org.apache.maven.plugins</groupId>
261313
<artifactId>maven-compiler-plugin</artifactId>
262-
<version>3.8.1</version>
314+
<version>3.14.0</version>
263315
<executions>
264316
<!-- Disable default executions -->
265317
<execution>
@@ -292,7 +344,10 @@ Here's an example configuration:
292344
</build>
293345
```
294346

295-
This configuration ensures the following:
347+
</tab>
348+
</tabs>
349+
350+
This configuration ensures that:
296351

297352
* Kotlin code is compiled first.
298353
* Java code is compiled after Kotlin and can reference Kotlin classes.

0 commit comments

Comments
 (0)