Skip to content

Commit cf502f6

Browse files
committed
update: simplified pom.xml
1 parent 2937485 commit cf502f6

File tree

3 files changed

+33
-444
lines changed

3 files changed

+33
-444
lines changed

docs/snippets/jvm-test-tutorial/pom.xml

Lines changed: 14 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<artifactId>junit-jupiter-api</artifactId>
3636
<scope>test</scope>
3737
</dependency>
38-
<!-- JUnit Jupiter engine is required at test runtime -->
38+
<!-- Add JUnit Jupiter engine for test runtime -->
3939
<dependency>
4040
<groupId>org.junit.jupiter</groupId>
4141
<artifactId>junit-jupiter-engine</artifactId>
@@ -47,7 +47,7 @@
4747
<artifactId>junit-jupiter-params</artifactId>
4848
<scope>test</scope>
4949
</dependency>
50-
<!-- Kotlin standard library needed to compile/run Kotlin tests -->
50+
<!-- Add Kotlin standard library to compile and run Kotlin tests -->
5151
<dependency>
5252
<groupId>org.jetbrains.kotlin</groupId>
5353
<artifactId>kotlin-stdlib</artifactId>
@@ -62,7 +62,7 @@
6262
</dependencies>
6363

6464
<build>
65-
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
65+
<pluginManagement><!-- lock down plugin versions to avoid using Maven defaults (can be moved to a parent pom file) -->
6666
<plugins>
6767
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
6868
<plugin>
@@ -99,103 +99,35 @@
9999
<artifactId>maven-project-info-reports-plugin</artifactId>
100100
<version>3.6.1</version>
101101
</plugin>
102-
103-
<!-- KOTLIN -->
104-
<plugin>
105-
<groupId>org.jetbrains.kotlin</groupId>
106-
<artifactId>kotlin-maven-plugin</artifactId>
107-
<version>${kotlin.version}</version>
108-
<extensions>true
109-
</extensions> <!-- You can set this option to automatically take information about lifecycles -->
110-
<executions>
111-
<execution>
112-
<id>compile</id>
113-
<goals>
114-
<goal>compile</goal> <!-- You can skip the <goals> element if you enable extensions for the plugin -->
115-
</goals>
116-
<configuration>
117-
<sourceDirs>
118-
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
119-
<sourceDir>${project.basedir}/src/main/java</sourceDir>
120-
</sourceDirs>
121-
</configuration>
122-
</execution>
123-
<execution>
124-
<id>test-compile</id>
125-
<goals>
126-
<goal>test-compile</goal> <!-- You can skip the <goals> element if you enable extensions for the plugin -->
127-
</goals>
128-
<configuration>
129-
<sourceDirs>
130-
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
131-
<sourceDir>${project.basedir}/src/test/java</sourceDir>
132-
</sourceDirs>
133-
</configuration>
134-
</execution>
135-
</executions>
136-
</plugin>
137-
<plugin>
138-
<groupId>org.apache.maven.plugins</groupId>
139-
<artifactId>maven-compiler-plugin</artifactId>
140-
<version>3.14.0</version>
141-
<executions>
142-
<!-- Replacing default-compile as it is treated specially by Maven -->
143-
<execution>
144-
<id>default-compile</id>
145-
<phase>none</phase>
146-
</execution>
147-
<!-- Replacing default-testCompile as it is treated specially by Maven -->
148-
<execution>
149-
<id>default-testCompile</id>
150-
<phase>none</phase>
151-
</execution>
152-
<execution>
153-
<id>java-compile</id>
154-
<phase>compile</phase>
155-
<goals>
156-
<goal>compile</goal>
157-
</goals>
158-
</execution>
159-
<execution>
160-
<id>java-test-compile</id>
161-
<phase>test-compile</phase>
162-
<goals>
163-
<goal>testCompile</goal>
164-
</goals>
165-
</execution>
166-
</executions>
167-
</plugin>
102+
<!-- No maven-compiler-plugin needed with Kotlin extensions -->
168103
</plugins>
169104
</pluginManagement>
170105
<plugins>
171-
<!-- Activate Kotlin compiler for main and test sources -->
106+
<!-- Activate Kotlin Maven plugin for main and test sources -->
172107
<plugin>
173108
<groupId>org.jetbrains.kotlin</groupId>
174109
<artifactId>kotlin-maven-plugin</artifactId>
175110
<version>${kotlin.version}</version>
176111
<extensions>true</extensions>
177112
<executions>
178113
<execution>
179-
<id>compile</id>
180-
<goals>
181-
<goal>compile</goal>
182-
</goals>
114+
<id>default-compile</id>
115+
<phase>compile</phase>
183116
<configuration>
184117
<sourceDirs>
185-
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
186-
<sourceDir>${project.basedir}/src/main/java</sourceDir>
118+
<sourceDir>src/main/kotlin</sourceDir>
119+
<!-- Ensure Kotlin code can reference Java code -->
120+
<sourceDir>src/main/java</sourceDir>
187121
</sourceDirs>
188122
</configuration>
189123
</execution>
190124
<execution>
191-
<id>test-compile</id>
192-
<goals>
193-
<goal>test-compile</goal>
194-
</goals>
125+
<id>default-test-compile</id>
126+
<phase>test-compile</phase>
195127
<configuration>
196128
<sourceDirs>
197-
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
198-
<sourceDir>${project.basedir}/src/test/java</sourceDir>
129+
<sourceDir>src/test/kotlin</sourceDir>
130+
<sourceDir>src/test/java</sourceDir>
199131
</sourceDirs>
200132
</configuration>
201133
</execution>

docs/topics/jvm/jvm-test-using-junit.md

Lines changed: 7 additions & 212 deletions
Original file line numberDiff line numberDiff line change
@@ -44,221 +44,16 @@ Before you start, make sure you have:
4444
<tab title="Maven" group-key="maven">
4545
4646
```xml
47-
<?xml version="1.0" encoding="UTF-8"?>
48-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
49-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
50-
<modelVersion>4.0.0</modelVersion>
51-
52-
<groupId>org.jetbrains.kotlin</groupId>
53-
<artifactId>kotlin-junit-complete</artifactId>
54-
<version>1.0-SNAPSHOT</version>
55-
56-
<name>kotlin-junit-complete</name>
57-
<url>https://kotlinlang.org/docs/jvm-test-using-junit.htm</url>
58-
59-
<properties>
60-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
61-
<maven.compiler.release>17</maven.compiler.release>
62-
<jexer.version>1.6.0</jexer.version>
63-
<kotlin.version>%kotlinVersion%</kotlin.version>
64-
</properties>
65-
66-
<dependencyManagement>
67-
<dependencies>
68-
<dependency>
69-
<groupId>org.junit</groupId>
70-
<artifactId>junit-bom</artifactId>
71-
<version>5.11.0</version>
72-
<type>pom</type>
73-
<scope>import</scope>
74-
</dependency>
75-
</dependencies>
76-
</dependencyManagement>
77-
78-
<dependencies>
79-
<dependency>
80-
<groupId>org.junit.jupiter</groupId>
81-
<artifactId>junit-jupiter-api</artifactId>
82-
<scope>test</scope>
83-
</dependency>
84-
<!-- JUnit Jupiter engine is required at test runtime -->
85-
<dependency>
86-
<groupId>org.junit.jupiter</groupId>
87-
<artifactId>junit-jupiter-engine</artifactId>
88-
<scope>test</scope>
89-
</dependency>
90-
<!-- Optionally: parameterized tests support -->
91-
<dependency>
92-
<groupId>org.junit.jupiter</groupId>
93-
<artifactId>junit-jupiter-params</artifactId>
94-
<scope>test</scope>
95-
</dependency>
96-
<!-- Kotlin standard library needed to compile/run Kotlin tests -->
97-
<dependency>
98-
<groupId>org.jetbrains.kotlin</groupId>
99-
<artifactId>kotlin-stdlib</artifactId>
100-
<version>${kotlin.version}</version>
101-
<scope>test</scope>
102-
</dependency>
103-
<dependency>
104-
<groupId>com.gitlab.klamonte</groupId>
105-
<artifactId>jexer</artifactId>
106-
<version>${jexer.version}</version>
107-
</dependency>
108-
</dependencies>
109-
110-
<build>
111-
<pluginManagement><!-- lock down plugin versions to avoid using Maven defaults (can be moved to a parent pom file) -->
112-
<plugins>
113-
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
114-
<plugin>
115-
<artifactId>maven-clean-plugin</artifactId>
116-
<version>3.4.0</version>
117-
</plugin>
118-
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
119-
<plugin>
120-
<artifactId>maven-resources-plugin</artifactId>
121-
<version>3.3.1</version>
122-
</plugin>
123-
<plugin>
124-
<artifactId>maven-surefire-plugin</artifactId>
125-
<version>3.3.0</version>
126-
</plugin>
127-
<plugin>
128-
<artifactId>maven-jar-plugin</artifactId>
129-
<version>3.4.2</version>
130-
</plugin>
131-
<plugin>
132-
<artifactId>maven-install-plugin</artifactId>
133-
<version>3.1.2</version>
134-
</plugin>
135-
<plugin>
136-
<artifactId>maven-deploy-plugin</artifactId>
137-
<version>3.1.2</version>
138-
</plugin>
139-
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
140-
<plugin>
141-
<artifactId>maven-site-plugin</artifactId>
142-
<version>3.12.1</version>
143-
</plugin>
144-
<plugin>
145-
<artifactId>maven-project-info-reports-plugin</artifactId>
146-
<version>3.6.1</version>
147-
</plugin>
148-
149-
<!-- KOTLIN -->
150-
<plugin>
151-
<groupId>org.jetbrains.kotlin</groupId>
152-
<artifactId>kotlin-maven-plugin</artifactId>
153-
<version>${kotlin.version}</version>
154-
<extensions>true
155-
</extensions> <!-- You can set this option to automatically take information about lifecycles -->
156-
<executions>
157-
<execution>
158-
<id>compile</id>
159-
<goals>
160-
<goal>compile</goal> <!-- You can skip the <goals> element if you enable extensions for the plugin -->
161-
</goals>
162-
<configuration>
163-
<sourceDirs>
164-
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
165-
<sourceDir>${project.basedir}/src/main/java</sourceDir>
166-
</sourceDirs>
167-
</configuration>
168-
</execution>
169-
<execution>
170-
<id>test-compile</id>
171-
<goals>
172-
<goal>test-compile</goal> <!-- You can skip the <goals> element if you enable extensions for the plugin -->
173-
</goals>
174-
<configuration>
175-
<sourceDirs>
176-
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
177-
<sourceDir>${project.basedir}/src/test/java</sourceDir>
178-
</sourceDirs>
179-
</configuration>
180-
</execution>
181-
</executions>
182-
</plugin>
183-
<plugin>
184-
<groupId>org.apache.maven.plugins</groupId>
185-
<artifactId>maven-compiler-plugin</artifactId>
186-
<version>3.14.0</version>
187-
<executions>
188-
<!-- Replacing default-compile as it's treated specifically by Maven -->
189-
<execution>
190-
<id>default-compile</id>
191-
<phase>none</phase>
192-
</execution>
193-
<!-- Replacing default-testCompile as it's treated specifically by Maven -->
194-
<execution>
195-
<id>default-testCompile</id>
196-
<phase>none</phase>
197-
</execution>
198-
<execution>
199-
<id>java-compile</id>
200-
<phase>compile</phase>
201-
<goals>
202-
<goal>compile</goal>
203-
</goals>
204-
</execution>
205-
<execution>
206-
<id>java-test-compile</id>
207-
<phase>test-compile</phase>
208-
<goals>
209-
<goal>testCompile</goal>
210-
</goals>
211-
</execution>
212-
</executions>
213-
</plugin>
214-
</plugins>
215-
</pluginManagement>
216-
<plugins>
217-
<!-- Activate Kotlin compiler for main and test sources -->
218-
<plugin>
219-
<groupId>org.jetbrains.kotlin</groupId>
220-
<artifactId>kotlin-maven-plugin</artifactId>
221-
<version>${kotlin.version}</version>
222-
<extensions>true</extensions>
223-
<executions>
224-
<execution>
225-
<id>compile</id>
226-
<goals>
227-
<goal>compile</goal>
228-
</goals>
229-
<configuration>
230-
<sourceDirs>
231-
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
232-
<sourceDir>${project.basedir}/src/main/java</sourceDir>
233-
</sourceDirs>
234-
</configuration>
235-
</execution>
236-
<execution>
237-
<id>test-compile</id>
238-
<goals>
239-
<goal>test-compile</goal>
240-
</goals>
241-
<configuration>
242-
<sourceDirs>
243-
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
244-
<sourceDir>${project.basedir}/src/test/java</sourceDir>
245-
</sourceDirs>
246-
</configuration>
247-
</execution>
248-
</executions>
249-
</plugin>
250-
</plugins>
251-
</build>
252-
</project>
25347
```
254-
{initial-collapse-state="collapsed" collapsible="true" collapsed-title="pom.xml file"}
48+
{src="jvm-test-tutorial/pom.xml" initial-collapse-state="collapsed" collapsible="true" collapsed-title="pom.xml file"}
25549
25650
* In the `<properties>` section, set the Kotlin version.
257-
* In the `<dependencies>` section, add the `kotlin-stdlib` dependency to compile and run Kotlin tests.
258-
* In the `<pluginManagement>` section, add and configure the `kotlin-maven-plugin` plugin.
259-
* In the `<pluginManagement>` section, configure the `maven-compiler-plugin` plugin to disable default compile phases,
260-
and compile Java after Kotlin.
261-
* In the `<plugins>` section, add the `kotlin-maven-plugin`.
51+
* In the `<dependencies>` section, add JUnit Jupiter dependencies and the `kotlin-stdlib` (test scope) to compile and
52+
run Kotlin tests.
53+
* In the `<build><plugins>` section, apply `kotlin-maven-plugin` with `extensions` enabled and configure `compile`
54+
and `test-compile` executions with `sourceDirs` for both Kotlin and Java.
55+
* You don't need to add `maven-compiler-plugin` to the `<build><pluginManagement>` section when using the Kotlin
56+
Maven plugin with extensions.
26257
26358
</tab>
26459
<tab title="Gradle" group-key="gradle">

0 commit comments

Comments
 (0)