Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import org.gradle.api.logging.Logger;
import org.gradle.api.logging.Logging;
import org.gradle.api.plugins.ApplicationPlugin;
import org.gradle.api.plugins.JavaPluginConvention;
import org.gradle.api.tasks.JavaExec;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.application.CreateStartScripts;

import java.io.File;
Expand Down Expand Up @@ -72,8 +74,13 @@ private void updateStartScriptsTask(Project project, JavaExec execTask, String m
private void updateJavaExecTask(JavaExec execTask, String moduleName) {
execTask.doFirst(task -> {

JavaPluginConvention javaConvention = execTask.getProject().getConvention().getPlugin(JavaPluginConvention.class);

SourceSet mainSourceSet = javaConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);

var moduleJvmArgs = new ArrayList<>(List.of(
"--module-path", execTask.getClasspath().getAsPath())
"--module-path", execTask.getClasspath().getAsPath(),
"--patch-module", moduleName + "=" + mainSourceSet.getOutput().getResourcesDir().toPath())
);
if (!moduleName.isEmpty()) {
moduleJvmArgs.addAll(List.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public void configureTestJava(Project project, String moduleName) {
JavaPluginConvention javaConvention = project.getConvention().getPlugin(JavaPluginConvention.class);

SourceSet testSourceSet = javaConvention.getSourceSets().getByName(SourceSet.TEST_SOURCE_SET_NAME);
SourceSet mainSourceSet = javaConvention.getSourceSets().getByName(SourceSet.MAIN_SOURCE_SET_NAME);
testJava.getExtensions().create("moduleOptions", TestModuleOptions.class, project);

testJava.doFirst(task -> {
Expand All @@ -38,7 +39,9 @@ public void configureTestJava(Project project, String moduleName) {

args.addAll(List.of(
"--module-path", testJava.getClasspath().getAsPath(),
"--patch-module", moduleName + "=" + testSourceSet.getJava().getOutputDir().toPath(),
"--patch-module", moduleName + "=" + testSourceSet.getJava().getOutputDir().toPath()
+ ":" + mainSourceSet.getOutput().getResourcesDir().toPath()
+ ":" + testSourceSet.getOutput().getResourcesDir().toPath(),
"--add-modules", "ALL-MODULE-PATH"
));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package examples.greeter;

import examples.greeter.api.Greeter;
import java.io.*;
import java.util.*;

public class Friendly implements Greeter {
@Override
public String hello() {
return "Hello and welcome!";
var stream = this.getClass().getResourceAsStream("/greeting.txt");
try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream, "utf-8"))) {
return reader.readLine();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
welcome
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ public static void main(String[] args) {
Greeter greeter = ServiceLoader.load(Greeter.class).findFirst().orElseThrow(() -> new RuntimeException("No Greeter found!"));
System.out.println(greeter.hello());

var resource = Runner.class.getResourceAsStream("/resourcetest.txt");
if(resource == null) {
throw new RuntimeException("Couldn't load resource");
}

ModuleLayer.boot().modules().stream()
.map(Module::getName)
.filter(m -> m.equals("java.sql"))
Expand Down
Empty file.