Skip to content

Commit

Permalink
fix #244 secondary launcher fails in Kotlin DSL
Browse files Browse the repository at this point in the history
  • Loading branch information
xzel23 authored and airsquared committed Feb 14, 2024
1 parent e6d9eaa commit dbeba1f
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class JlinkPluginExtension {
action.execute(launcherData.get())
}

void secondaryLauncher(Action<LauncherData> action) {
void secondaryLauncher(Action<SecondaryLauncherData> action) {
def ld = new SecondaryLauncherData(null)
ld.moduleName = moduleName.get()
Util.addToListProperty(secondaryLaunchers, ld)
Expand Down
18 changes: 18 additions & 0 deletions src/test/groovy/org/beryx/jlink/JlinkPluginSpec.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,24 @@ class JlinkPluginSpec extends Specification {
checkOutput(result, 'howdy', 'Howdy!')
}

def "should create image of project with multiple launchers using kotlin DSL"() {
when:

File buildFile = setUpBuild('multi-launch-kotlin-dsl')
BuildResult result = GradleRunner.create()
.withDebug(true)
.withGradleVersion('7.6')
.withProjectDir(testProjectDir.toFile())
.withPluginClasspath()
.withArguments(JlinkPlugin.TASK_NAME_JLINK, "-is")
.build();

then:
checkOutput(result, 'hello', 'Hello, world!')
checkOutput(result, 'helloAgain', 'Hello again!')
checkOutput(result, 'howdy', 'Howdy!')
}

private boolean checkOutput(BuildResult result, String imageName, String expectedOutput) {
def imageBinDir = new File(testProjectDir.toFile(), 'build/image/bin')
def launcherExt = OperatingSystem.current.windows ? '.bat' : ''
Expand Down
35 changes: 35 additions & 0 deletions src/test/resources/multi-launch-kotlin-dsl/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
plugins {
id("org.javamodularity.moduleplugin") version "1.8.12"
id("org.beryx.jlink")
}

repositories {
mavenCentral()
}

extra["moduleName"] = "org.example.multi"

application {
mainClass.set("org.example.multi.Hello")
}

jlink {
launcher {
name = "hello"
noConsole = false
jvmArgs = listOf(
"-Xms512m",
"-Xmx4g",
"-XX:+UseShenandoahGC"
)
}
secondaryLauncher {
name = "helloAgain"
mainClass = "org.example.multi.HelloAgain"
}
secondaryLauncher {
name = "howdy"
moduleName= "org.example.multi"
mainClass = "org.example.multi.Howdy"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = "multi-launch-kotlin-dsl"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module org.example.multi {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.example.multi;

public class Hello {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.example.multi;

public class HelloAgain {
public static void main(String[] args) {
System.out.println("Hello again!");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.example.multi;

public class Howdy {
public static void main(String[] args) {
System.out.println("Howdy!");
}
}

0 comments on commit dbeba1f

Please sign in to comment.