Skip to content

Commit

Permalink
16: Fix multi-release Jar setup
Browse files Browse the repository at this point in the history
  • Loading branch information
jjohannes committed Jan 23, 2024
1 parent 8459730 commit ce77c84
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,12 @@ plugins {
id("my-java-base")
id("application")
}

tasks.register<JavaExec>("runJava17") {
classpath = configurations.runtimeClasspath.get() + files(tasks.jar)
javaLauncher.set(javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(17)
})
mainClass = application.mainClass
group = "application"
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ jvm.registerJvmLanguageSourceDirectory(sourceSets.main.get(), "java17") {
classpath = sourceSets.main.get().compileClasspath
doLast {
val destRoot = destinationDirectory.get().asFile
val destVersion17 = File(destRoot, "META-INF/version/17").also { it.mkdirs() }
val destVersions = File(destRoot, "META-INF/versions/17").also { it.mkdirs() }
destVersions.deleteRecursively()
destVersions.mkdirs()
destRoot.listFiles()?.forEach {
if (it.name != "META-INF") {
Files.move(it.toPath(), File(destVersion17, it.name).toPath())
Files.move(it.toPath(), File(destVersions, it.name).toPath())
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public final class MyApplication {

public static void main(final String[] args) {
Service.printMessage(new MessageModel(readeMessageTxt()));
Service.printMessage(new MessageModel("Java 11"));
}

static String readeMessageTxt() {
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package myproject;

import myproject.data.MessageModel;
import myproject.services.Service;

import java.util.Scanner;

public final class MyApplication {

public static void main(final String[] args) {
Service.printMessage(new MessageModel(readeMessageTxt()));
Service.printMessage(new MessageModel("Java 17"));
}

static String readeMessageTxt() {
//noinspection ConstantConditions
return new Scanner(MyApplication.class.getResourceAsStream("message.txt"))
.useDelimiter("\n").next();
}
}

0 comments on commit ce77c84

Please sign in to comment.