private static void fixTestTaskSources(@NonNull Test testTask) { // We are running in afterEvaluate, so the JavaBasePlugin has already added a // callback to add test classes to the list of source files of the newly created task. // The problem is that we haven't configured the test classes yet (JavaBasePlugin // assumes all Test tasks are fully configured at this point), so we have to remove the // "directory null" entry from source files and add the right value. // // This is an ugly hack, since we assume sourceFiles is an instance of // DefaultConfigurableFileCollection. ((DefaultConfigurableFileCollection) testTask.getInputs().getSourceFiles()).getFrom().clear(); }
private void configureTestTask(final Project project) { final Test testTask = (Test) project.getTasks().findByName(JavaPlugin.TEST_TASK_NAME); final SourceSet test = ((SourceSetContainer) project.getProperties().get("sourceSets")).getByName("test"); final JavaModule module = (JavaModule) project.getExtensions().getByName(EXTENSION_NAME); testTask.getInputs().property("moduleName", module.geName()); testTask.doFirst(new Action<Task>() { @Override public void execute(Task task) { List<String> args = new ArrayList<>(); args.add("--module-path"); args.add(testTask.getClasspath().getAsPath()); args.add("--add-modules"); args.add("ALL-MODULE-PATH"); args.add("--add-reads"); args.add(module.geName() + "=junit"); args.add("--patch-module"); args.add(module.geName() + "=" + test.getJava().getOutputDir()); testTask.setJvmArgs(args); testTask.setClasspath(project.files()); } }); }