Skip to content

Commit 2c7a773

Browse files
authored
Merge pull request #848 from navikt/conservative-compile-targets
build: set kotlin compiler targets for user compatibility
2 parents 71e8134 + 19560a2 commit 2c7a773

File tree

6 files changed

+57
-30
lines changed

6 files changed

+57
-30
lines changed

build.gradle.kts

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import java.time.Duration
22
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
33
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
4+
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
45

56
val assertjVersion = "3.27.3"
67
val kotlinLoggingVersion = "3.0.5"
@@ -10,7 +11,6 @@ val mockWebServerVersion = "4.12.0"
1011
val jacksonVersion = "2.19.0"
1112
val nettyVersion = "4.2.2.Final"
1213
val junitJupiterVersion = "5.13.0"
13-
val kotlinVersion = "2.1.21"
1414
val freemarkerVersion = "2.3.34"
1515
val kotestVersion = "5.9.1"
1616
val bouncyCastleVersion = "1.81"
@@ -24,7 +24,7 @@ val mainClassKt = "no.nav.security.mock.oauth2.StandaloneMockOAuth2ServerKt"
2424

2525
plugins {
2626
application
27-
kotlin("jvm") version "2.1.21"
27+
alias(libs.plugins.kotlin.jvm) // refers to plugin declared in gradle/libs.versions.toml
2828
id("se.patrikerdes.use-latest-versions") version "0.2.18"
2929
id("com.github.ben-manes.versions") version "0.52.0"
3030
id("org.jmailen.kotlinter") version "5.1.0"
@@ -49,6 +49,28 @@ java {
4949
withSourcesJar()
5050
}
5151

52+
kotlin {
53+
val kotlinTarget = libs.versions.kotlinTarget
54+
val kotlinTargetVersion = kotlinTarget.map {
55+
KotlinVersion.fromVersion(it.toKotlinMinor())
56+
}
57+
58+
compilerOptions {
59+
languageVersion = kotlinTargetVersion
60+
apiVersion = kotlinTargetVersion
61+
// Syncing Kotlin JVM target with Java plugin JVM target
62+
jvmTarget = JvmTarget.JVM_17
63+
}
64+
65+
// Setting core libraries version to manage compile and runtime dependencies exposed in the published artifact metadata
66+
// These will become transitive dependencies for our users.
67+
// Core libraries for JVM are kotlin-stdlib and kotlin-test.
68+
coreLibrariesVersion = kotlinTarget.get()
69+
}
70+
71+
// 1.7.21 => 1.7, 1.9 => 1.9
72+
fun String.toKotlinMinor() = split(".").take(2).joinToString(".")
73+
5274
apply(plugin = "org.jmailen.kotlinter")
5375

5476
repositories {
@@ -73,7 +95,7 @@ dependencies {
7395
testImplementation("org.junit.jupiter:junit-jupiter-params:$junitJupiterVersion")
7496
testImplementation("io.kotest:kotest-runner-junit5-jvm:$kotestVersion") // for kotest framework
7597
testImplementation("io.kotest:kotest-assertions-core-jvm:$kotestVersion") // for kotest core jvm assertions
76-
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5:$kotlinVersion")
98+
testImplementation("org.jetbrains.kotlin:kotlin-test-junit5") // uses version matching kotlin-jvm plugin
7799
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitJupiterVersion")
78100
// example use with different frameworks
79101
testImplementation("org.springframework.boot:spring-boot-starter-webflux:$springBootVersion")
@@ -289,12 +311,6 @@ tasks {
289311
}
290312
}
291313

292-
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
293-
compilerOptions {
294-
jvmTarget.set(JvmTarget.JVM_17)
295-
}
296-
}
297-
298314
withType<Test> {
299315
jvmArgs("--add-opens=java.base/java.util=ALL-UNNAMED")
300316
useJUnitPlatform()
@@ -311,6 +327,6 @@ tasks {
311327
}
312328

313329
withType<Wrapper> {
314-
gradleVersion = "8.9"
330+
gradleVersion = "8.14.1"
315331
}
316332
}

gradle/libs.versions.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[versions]
2+
kotlinTarget = "1.9.0" # Minimum supported Kotlin version for consumers of the library
3+
kotlinToolchain = "2.1.21" # Actual version used by tooling within this project
4+
5+
[plugins]
6+
kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlinToolchain" }

gradle/wrapper/gradle-wrapper.jar

-19.7 KB
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.1-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

gradlew

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
1717
#
18+
# SPDX-License-Identifier: Apache-2.0
19+
#
1820

1921
##############################################################################
2022
#
@@ -55,7 +57,7 @@
5557
# Darwin, MinGW, and NonStop.
5658
#
5759
# (3) This script is generated from the Groovy template
58-
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
60+
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
5961
# within the Gradle project.
6062
#
6163
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -84,7 +86,8 @@ done
8486
# shellcheck disable=SC2034
8587
APP_BASE_NAME=${0##*/}
8688
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
87-
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
89+
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
90+
' "$PWD" ) || exit
8891

8992
# Use the maximum available, or set MAX_FD != -1 to use that value.
9093
MAX_FD=maximum
@@ -145,15 +148,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
145148
case $MAX_FD in #(
146149
max*)
147150
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
148-
# shellcheck disable=SC3045
151+
# shellcheck disable=SC2039,SC3045
149152
MAX_FD=$( ulimit -H -n ) ||
150153
warn "Could not query maximum file descriptor limit"
151154
esac
152155
case $MAX_FD in #(
153156
'' | soft) :;; #(
154157
*)
155158
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
156-
# shellcheck disable=SC3045
159+
# shellcheck disable=SC2039,SC3045
157160
ulimit -n "$MAX_FD" ||
158161
warn "Could not set maximum file descriptor limit to $MAX_FD"
159162
esac
@@ -202,11 +205,11 @@ fi
202205
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
203206
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
204207

205-
# Collect all arguments for the java command;
206-
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
207-
# shell script including quotes and variable substitutions, so put them in
208-
# double quotes to make sure that they get re-expanded; and
209-
# * put everything else in single quotes, so that it's not re-expanded.
208+
# Collect all arguments for the java command:
209+
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
210+
# and any embedded shellness will be escaped.
211+
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
212+
# treated as '${Hostname}' itself on the command line.
210213

211214
set -- \
212215
"-Dorg.gradle.appname=$APP_BASE_NAME" \

gradlew.bat

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
@rem See the License for the specific language governing permissions and
1414
@rem limitations under the License.
1515
@rem
16+
@rem SPDX-License-Identifier: Apache-2.0
17+
@rem
1618

1719
@if "%DEBUG%"=="" @echo off
1820
@rem ##########################################################################
@@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
4345
%JAVA_EXE% -version >NUL 2>&1
4446
if %ERRORLEVEL% equ 0 goto execute
4547

46-
echo.
47-
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
48-
echo.
49-
echo Please set the JAVA_HOME variable in your environment to match the
50-
echo location of your Java installation.
48+
echo. 1>&2
49+
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
50+
echo. 1>&2
51+
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
52+
echo location of your Java installation. 1>&2
5153

5254
goto fail
5355

@@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
5759

5860
if exist "%JAVA_EXE%" goto execute
5961

60-
echo.
61-
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
62-
echo.
63-
echo Please set the JAVA_HOME variable in your environment to match the
64-
echo location of your Java installation.
62+
echo. 1>&2
63+
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
64+
echo. 1>&2
65+
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
66+
echo location of your Java installation. 1>&2
6567

6668
goto fail
6769

0 commit comments

Comments
 (0)