Skip to content

Commit fd07bfd

Browse files
committed
Polish "Add runApplication() Kotlin top level function"
Closes gh-10511
1 parent 605ede8 commit fd07bfd

File tree

6 files changed

+139
-107
lines changed

6 files changed

+139
-107
lines changed

spring-boot-project/spring-boot-dependencies/pom.xml

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2245,26 +2245,6 @@
22452245
<artifactId>jdom2</artifactId>
22462246
<version>${jdom2.version}</version>
22472247
</dependency>
2248-
<dependency>
2249-
<groupId>org.jolokia</groupId>
2250-
<artifactId>jolokia-core</artifactId>
2251-
<version>${jolokia.version}</version>
2252-
</dependency>
2253-
<dependency>
2254-
<groupId>org.jooq</groupId>
2255-
<artifactId>jooq</artifactId>
2256-
<version>${jooq.version}</version>
2257-
</dependency>
2258-
<dependency>
2259-
<groupId>org.jooq</groupId>
2260-
<artifactId>jooq-meta</artifactId>
2261-
<version>${jooq.version}</version>
2262-
</dependency>
2263-
<dependency>
2264-
<groupId>org.jooq</groupId>
2265-
<artifactId>jooq-codegen</artifactId>
2266-
<version>${jooq.version}</version>
2267-
</dependency>
22682248
<dependency>
22692249
<groupId>org.jetbrains.kotlin</groupId>
22702250
<artifactId>kotlin-reflect</artifactId>
@@ -2285,6 +2265,26 @@
22852265
<artifactId>kotlin-stdlib-jre8</artifactId>
22862266
<version>${kotlin.version}</version>
22872267
</dependency>
2268+
<dependency>
2269+
<groupId>org.jolokia</groupId>
2270+
<artifactId>jolokia-core</artifactId>
2271+
<version>${jolokia.version}</version>
2272+
</dependency>
2273+
<dependency>
2274+
<groupId>org.jooq</groupId>
2275+
<artifactId>jooq</artifactId>
2276+
<version>${jooq.version}</version>
2277+
</dependency>
2278+
<dependency>
2279+
<groupId>org.jooq</groupId>
2280+
<artifactId>jooq-meta</artifactId>
2281+
<version>${jooq.version}</version>
2282+
</dependency>
2283+
<dependency>
2284+
<groupId>org.jooq</groupId>
2285+
<artifactId>jooq-codegen</artifactId>
2286+
<version>${jooq.version}</version>
2287+
</dependency>
22882288
<dependency>
22892289
<groupId>org.liquibase</groupId>
22902290
<artifactId>liquibase-core</artifactId>
@@ -2881,6 +2881,11 @@
28812881
<build>
28822882
<pluginManagement>
28832883
<plugins>
2884+
<plugin>
2885+
<groupId>kotlin-maven-plugin</groupId>
2886+
<artifactId>org.jetbrains.kotlin</artifactId>
2887+
<version>${kotlin.version}</version>
2888+
</plugin>
28842889
<plugin>
28852890
<groupId>org.jooq</groupId>
28862891
<artifactId>jooq-codegen-maven</artifactId>
@@ -3024,11 +3029,6 @@
30243029
<artifactId>flyway-maven-plugin</artifactId>
30253030
<version>${flyway.version}</version>
30263031
</plugin>
3027-
<plugin>
3028-
<groupId>kotlin-maven-plugin</groupId>
3029-
<artifactId>org.jetbrains.kotlin</artifactId>
3030-
<version>${kotlin.version}</version>
3031-
</plugin>
30323032
<plugin>
30333033
<groupId>pl.project13.maven</groupId>
30343034
<artifactId>git-commit-id-plugin</artifactId>

spring-boot-project/spring-boot-parent/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,14 @@
268268
<build>
269269
<pluginManagement>
270270
<plugins>
271+
<plugin>
272+
<groupId>org.jetbrains.kotlin</groupId>
273+
<artifactId>kotlin-maven-plugin</artifactId>
274+
<version>${kotlin.version}</version>
275+
<configuration>
276+
<jvmTarget>${java.version}</jvmTarget>
277+
</configuration>
278+
</plugin>
271279
<plugin>
272280
<groupId>org.asciidoctor</groupId>
273281
<artifactId>asciidoctor-maven-plugin</artifactId>

spring-boot-project/spring-boot-starters/spring-boot-starter-parent/pom.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,30 @@
6060
<pluginManagement>
6161
<plugins>
6262
<!-- Apply more sensible defaults for user projects -->
63+
<plugin>
64+
<groupId>org.jetbrains.kotlin</groupId>
65+
<artifactId>kotlin-maven-plugin</artifactId>
66+
<version>${kotlin.version}</version>
67+
<configuration>
68+
<jvmTarget>${java.version}</jvmTarget>
69+
</configuration>
70+
<executions>
71+
<execution>
72+
<id>compile</id>
73+
<phase>compile</phase>
74+
<goals>
75+
<goal>compile</goal>
76+
</goals>
77+
</execution>
78+
<execution>
79+
<id>test-compile</id>
80+
<phase>test-compile</phase>
81+
<goals>
82+
<goal>test-compile</goal>
83+
</goals>
84+
</execution>
85+
</executions>
86+
</plugin>
6387
<plugin>
6488
<groupId>org.apache.maven.plugins</groupId>
6589
<artifactId>maven-compiler-plugin</artifactId>

spring-boot-project/spring-boot/pom.xml

Lines changed: 64 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -13,79 +13,6 @@
1313
<properties>
1414
<main.basedir>${basedir}/../..</main.basedir>
1515
</properties>
16-
<build>
17-
<plugins>
18-
<plugin>
19-
<artifactId>kotlin-maven-plugin</artifactId>
20-
<groupId>org.jetbrains.kotlin</groupId>
21-
<version>${kotlin.version}</version>
22-
<configuration>
23-
<jvmTarget>${java.version}</jvmTarget>
24-
</configuration>
25-
<executions>
26-
<execution>
27-
<id>compile</id>
28-
<phase>compile</phase>
29-
<goals>
30-
<goal>compile</goal>
31-
</goals>
32-
<configuration>
33-
<sourceDirs>
34-
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
35-
<sourceDir>${project.basedir}/src/main/java</sourceDir>
36-
</sourceDirs>
37-
</configuration>
38-
</execution>
39-
<execution>
40-
<id>test-compile</id>
41-
<phase>test-compile</phase>
42-
<goals>
43-
<goal>test-compile</goal>
44-
</goals>
45-
<configuration>
46-
<sourceDirs>
47-
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
48-
<sourceDir>${project.basedir}/src/test/java</sourceDir>
49-
</sourceDirs>
50-
</configuration>
51-
</execution>
52-
</executions>
53-
</plugin>
54-
<plugin>
55-
<groupId>org.apache.maven.plugins</groupId>
56-
<artifactId>maven-compiler-plugin</artifactId>
57-
<configuration>
58-
<source>${java.version}</source>
59-
<target>${java.version}</target>
60-
<parameters>true</parameters>
61-
</configuration>
62-
<executions>
63-
<execution>
64-
<id>default-compile</id>
65-
<phase>none</phase>
66-
</execution>
67-
<execution>
68-
<id>default-testCompile</id>
69-
<phase>none</phase>
70-
</execution>
71-
<execution>
72-
<id>java-compile</id>
73-
<phase>compile</phase>
74-
<goals>
75-
<goal>compile</goal>
76-
</goals>
77-
</execution>
78-
<execution>
79-
<id>java-test-compile</id>
80-
<phase>test-compile</phase>
81-
<goals>
82-
<goal>testCompile</goal>
83-
</goals>
84-
</execution>
85-
</executions>
86-
</plugin>
87-
</plugins>
88-
</build>
8916
<dependencies>
9017
<!-- Compile -->
9118
<dependency>
@@ -460,4 +387,68 @@
460387
<scope>test</scope>
461388
</dependency>
462389
</dependencies>
390+
<build>
391+
<plugins>
392+
<plugin>
393+
<groupId>org.jetbrains.kotlin</groupId>
394+
<artifactId>kotlin-maven-plugin</artifactId>
395+
<executions>
396+
<execution>
397+
<id>compile</id>
398+
<phase>compile</phase>
399+
<goals>
400+
<goal>compile</goal>
401+
</goals>
402+
<configuration>
403+
<sourceDirs>
404+
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
405+
<sourceDir>${project.basedir}/src/main/java</sourceDir>
406+
</sourceDirs>
407+
</configuration>
408+
</execution>
409+
<execution>
410+
<id>test-compile</id>
411+
<phase>test-compile</phase>
412+
<goals>
413+
<goal>test-compile</goal>
414+
</goals>
415+
<configuration>
416+
<sourceDirs>
417+
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
418+
<sourceDir>${project.basedir}/src/test/java</sourceDir>
419+
</sourceDirs>
420+
</configuration>
421+
</execution>
422+
</executions>
423+
</plugin>
424+
<plugin>
425+
<groupId>org.apache.maven.plugins</groupId>
426+
<artifactId>maven-compiler-plugin</artifactId>
427+
<executions>
428+
<execution>
429+
<id>default-compile</id>
430+
<phase>none</phase>
431+
</execution>
432+
<execution>
433+
<id>default-testCompile</id>
434+
<phase>none</phase>
435+
</execution>
436+
<execution>
437+
<id>java-compile</id>
438+
<phase>compile</phase>
439+
<goals>
440+
<goal>compile</goal>
441+
</goals>
442+
</execution>
443+
<execution>
444+
<id>java-test-compile</id>
445+
<phase>test-compile</phase>
446+
<goals>
447+
<goal>testCompile</goal>
448+
</goals>
449+
</execution>
450+
</executions>
451+
</plugin>
452+
</plugins>
453+
</build>
463454
</project>

spring-boot-project/spring-boot/src/main/kotlin/org/springframework/boot/SpringApplicationExtensions.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717
package org.springframework.boot
1818

1919
import org.springframework.context.ConfigurableApplicationContext
20+
2021
import kotlin.reflect.KClass
2122

2223

2324
/**
24-
* Top level function acting as a Kotlin shortcut allowing to write `runApplication<FooApplication>(arg1, arg2)`
25-
* instead of `SpringApplication.run(FooApplication::class.java, arg1, arg2)`.
25+
* Top level function acting as a Kotlin shortcut allowing to write
26+
* `runApplication<FooApplication>(arg1, arg2)` instead of
27+
* `SpringApplication.run(FooApplication::class.java, arg1, arg2)`.
2628
*
2729
* @author Sebastien Deleuze
2830
* @since 2.0.0
@@ -31,8 +33,10 @@ inline fun <reified T : Any> runApplication(vararg args: String): ConfigurableAp
3133
SpringApplication.run(T::class.java, *args)
3234

3335
/**
34-
* Top level function acting as a Kotlin shortcut allowing to write `runApplication<FooApplication>(arg1, arg2) { // SpringApplication customization ... }`
35-
* instead of instantiating `SpringApplication` class, customize it and then invoking `run(arg1, arg2)`.
36+
* Top level function acting as a Kotlin shortcut allowing to write
37+
* `runApplication<FooApplication>(arg1, arg2) { // SpringApplication customization ... }`
38+
* instead of instantiating `SpringApplication` class, customize it and then invoking
39+
* `run(arg1, arg2)`.
3640
*
3741
* @author Sebastien Deleuze
3842
* @since 2.0.0
@@ -44,7 +48,8 @@ inline fun <reified T : Any> runApplication(vararg args: String, init: SpringApp
4448
/**
4549
* Top level function acting as a Kotlin shortcut allowing to write
4650
* `runApplication(arrayOf(FooApplication::class, FooConfiguration::class), arg1, arg2) { // Optional SpringApplication customization ... }`
47-
* instead of instantiating `SpringApplication` class, customize it and then invoking `run(arrayOf(arg1, arg2))`.`
51+
* instead of instantiating `SpringApplication` class, customize it and then invoking
52+
* `run(arrayOf(arg1, arg2))`.`
4853
*
4954
* @author Sebastien Deleuze
5055
* @since 2.0.0

spring-boot-project/spring-boot/src/test/kotlin/org/springframework/boot/SpringApplicationExtensionsTests.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@
1515
*/
1616
package org.springframework.boot
1717

18-
import org.junit.Assert.*
18+
import org.junit.Assert.assertArrayEquals
19+
import org.junit.Assert.assertEquals
20+
import org.junit.Assert.assertNotNull
21+
import org.junit.Assert.assertTrue
1922
import org.junit.Test
23+
2024
import org.springframework.beans.factory.getBean
21-
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory
25+
import org.springframework.boot.web.servlet.server.MockServletWebServerFactory
2226
import org.springframework.context.annotation.Bean
2327
import org.springframework.context.annotation.Configuration
2428
import org.springframework.core.env.StandardEnvironment
@@ -110,8 +114,8 @@ class SpringApplicationExtensionsTests {
110114
internal open class ExampleWebConfig {
111115

112116
@Bean
113-
open fun webServer(): TomcatServletWebServerFactory {
114-
return TomcatServletWebServerFactory(0)
117+
open fun webServer(): MockServletWebServerFactory {
118+
return MockServletWebServerFactory()
115119
}
116120
}
117121

0 commit comments

Comments
 (0)