Skip to content

Commit a2385d6

Browse files
authored
Merge pull request #28 from navikt/update-jar-plugin-39c0c98
Oppdater buildSrc og jar plugin
2 parents 75f378f + 09f30b0 commit a2385d6

File tree

8 files changed

+103
-18
lines changed

8 files changed

+103
-18
lines changed

Dockerfile

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
FROM gcr.io/distroless/java17-debian11
2-
COPY build/libs/tms-statistikk-all.jar app/app.jar
3-
ENV PORT=8080
4-
EXPOSE $PORT
5-
WORKDIR app
6-
CMD ["app.jar"]
1+
FROM ghcr.io/navikt/baseimages/temurin:21
2+
3+
ENV JAVA_OPTS='-XX:MaxRAMPercentage=75'
4+
5+
COPY build/libs/*.jar ./

build.gradle.kts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import org.gradle.api.tasks.testing.logging.TestExceptionFormat
33
plugins {
44
kotlin("jvm").version(Kotlin.version)
55

6-
id(Shadow.pluginId) version (Shadow.version)
6+
id(TmsJarBundling.plugin)
77

88
application
99
}
1010

1111
kotlin {
1212
jvmToolchain {
13-
languageVersion.set(JavaLanguageVersion.of(17))
13+
languageVersion.set(JavaLanguageVersion.of(21))
1414
}
1515
}
1616

@@ -58,12 +58,6 @@ application {
5858
mainClass.set("no.nav.tms.statistikk.ApplicationKt")
5959
}
6060

61-
tasks {
62-
shadowJar {
63-
mergeServiceFiles()
64-
}
65-
}
66-
6761
tasks {
6862
withType<Test> {
6963
useJUnitPlatform()

buildSrc/build.gradle.kts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
plugins {
22
`kotlin-dsl`
3+
`maven-publish`
34
}
45

56
repositories {
@@ -8,6 +9,21 @@ repositories {
89

910
kotlin {
1011
jvmToolchain {
11-
languageVersion.set(JavaLanguageVersion.of(17))
12+
languageVersion.set(JavaLanguageVersion.of(21))
13+
}
14+
}
15+
16+
gradlePlugin {
17+
plugins {
18+
create("jar-bundling") {
19+
id = "no.nav.tms.jar-bundling"
20+
implementationClass = "JarBundling"
21+
}
22+
}
23+
}
24+
25+
publishing {
26+
repositories {
27+
mavenLocal()
1228
}
1329
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import org.gradle.api.DefaultTask
2+
import org.gradle.api.Plugin
3+
import org.gradle.api.Project
4+
import org.gradle.api.plugins.JavaApplication
5+
import org.gradle.api.tasks.Input
6+
import org.gradle.api.tasks.TaskAction
7+
import org.gradle.jvm.tasks.Jar
8+
import java.io.File
9+
10+
// Managed by tms-dependency-admin.
11+
12+
abstract class JarBundling : Plugin<Project> {
13+
14+
override fun apply(target: Project) {
15+
16+
val configureTask = target.tasks.register("configureJar", ConfigureJarTask::class.java) {
17+
this.application = target
18+
19+
val classes = target.tasks.named("classes")
20+
21+
dependsOn(classes)
22+
}
23+
24+
val packageTask = target.tasks.register("packageJar", BundleJarsTask::class.java) {
25+
this.application = target
26+
}
27+
28+
target.tasks.withType(Jar::class.java) {
29+
dependsOn(configureTask)
30+
finalizedBy(packageTask)
31+
}
32+
}
33+
}
34+
35+
abstract class ConfigureJarTask : DefaultTask() {
36+
@Input
37+
lateinit var application: Project
38+
39+
@TaskAction
40+
fun action() {
41+
application.tasks.withType(Jar::class.java) {
42+
43+
val javaApplication = application.extensions.getByType(JavaApplication::class.java)
44+
45+
val mainClassName = javaApplication.mainClass
46+
47+
archiveBaseName.set("app")
48+
manifest {
49+
val classpath = application.configurations.getByName("runtimeClasspath")
50+
attributes["Main-Class"] = mainClassName
51+
attributes["Class-Path"] = classpath.joinToString(separator = " ") {
52+
it.name
53+
}
54+
}
55+
}
56+
}
57+
}
58+
59+
abstract class BundleJarsTask : DefaultTask() {
60+
@Input
61+
lateinit var application: Project
62+
63+
@TaskAction
64+
fun action() {
65+
val classpath = application.configurations.getByName("runtimeClasspath")
66+
67+
classpath.forEach {
68+
val file = File("${application.layout.buildDirectory.get()}/libs/${it.name}")
69+
if (!file.exists()) it.copyTo(file)
70+
}
71+
}
72+
}

gradle/wrapper/gradle-wrapper.jar

130 Bytes
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.7-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

gradlew

Lines changed: 4 additions & 2 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,7 @@ 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\n' "$PWD" ) || exit
8890

8991
# Use the maximum available, or set MAX_FD != -1 to use that value.
9092
MAX_FD=maximum

gradlew.bat

Lines changed: 2 additions & 0 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 ##########################################################################

0 commit comments

Comments
 (0)