-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from navikt/update-jar-plugin-39c0c98
Oppdater buildSrc og jar plugin
- Loading branch information
Showing
6 changed files
with
97 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
FROM gcr.io/distroless/java17-debian11 | ||
COPY build/libs/tms-varsel-api-all.jar app/app.jar | ||
ENV PORT=8080 | ||
EXPOSE $PORT | ||
WORKDIR app | ||
CMD ["app.jar"] | ||
FROM ghcr.io/navikt/baseimages/temurin:21 | ||
|
||
ENV JAVA_OPTS='-XX:MaxRAMPercentage=75' | ||
|
||
COPY build/libs/*.jar ./ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.api.plugins.JavaApplication | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.TaskAction | ||
import org.gradle.jvm.tasks.Jar | ||
import java.io.File | ||
|
||
// Managed by tms-dependency-admin. | ||
|
||
abstract class JarBundling : Plugin<Project> { | ||
|
||
override fun apply(target: Project) { | ||
|
||
val configureTask = target.tasks.register("configureJar", ConfigureJarTask::class.java) { | ||
this.application = target | ||
|
||
val classes = target.tasks.named("classes") | ||
|
||
dependsOn(classes) | ||
} | ||
|
||
val packageTask = target.tasks.register("packageJar", BundleJarsTask::class.java) { | ||
this.application = target | ||
} | ||
|
||
target.tasks.withType(Jar::class.java) { | ||
dependsOn(configureTask) | ||
finalizedBy(packageTask) | ||
} | ||
} | ||
} | ||
|
||
abstract class ConfigureJarTask : DefaultTask() { | ||
@Input | ||
lateinit var application: Project | ||
|
||
@TaskAction | ||
fun action() { | ||
application.tasks.withType(Jar::class.java) { | ||
|
||
val javaApplication = application.extensions.getByType(JavaApplication::class.java) | ||
|
||
val mainClassName = javaApplication.mainClass | ||
|
||
archiveBaseName.set("app") | ||
manifest { | ||
val classpath = application.configurations.getByName("runtimeClasspath") | ||
attributes["Main-Class"] = mainClassName | ||
attributes["Class-Path"] = classpath.joinToString(separator = " ") { | ||
it.name | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
abstract class BundleJarsTask : DefaultTask() { | ||
@Input | ||
lateinit var application: Project | ||
|
||
@TaskAction | ||
fun action() { | ||
val classpath = application.configurations.getByName("runtimeClasspath") | ||
|
||
classpath.forEach { | ||
val file = File("${application.layout.buildDirectory.get()}/libs/${it.name}") | ||
if (!file.exists()) it.copyTo(file) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters