External library (JUnit 5 and JavaFX)
submission guide for Assignment 2
Overview
The assignment specification and marking criteria for Assignment 2 require you to submit a project that works in IntelliJ out of the box, with penalties assessed if it doesn’t. This leads to a problem when it comes to submitting projects with external libraries, as the paths to these libraries may not be the same on the marker’s computer. This guide will tell you what we recommend you do to avoid getting penalised, and how the markers will go about setting up the environment to mark your assignment.
JUnit 5
Every assignment submitted should use JUnit 5, so these are instructions everyone should pay attention to. For a JUnit 5 project to work, four libraries are required:
• apiguardian
• junit-jupiter-api
• junit-platform-commons • opentest4j
(depending on what you use within JUnit, one or more might be optional, but to minimise headaches we recommend using all 4)
For those libraries to be recognised and used, they must be configured as dependencies in the IntelliJ project (Project StructureModulesDependencies). If the project is configured with separate test and source directories (that is, separate directory structures each marked as ‘Sources Root’ and ‘Test Sources Root’ respectively) the JUnit 5 dependencies can be scoped as ‘Test’, but otherwise they should be scoped as ‘Compile’.
These libraries can be downloaded manually and then added to your project, but the easiest and most foolproof way of adding them might be to let IntelliJ do it for you. Paste the following into the import section of a .java source file in your project:
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.*;
IntelliJ will then highlight the ‘junit’ part in red. Place your cursor on that and then press Alt+Enter. This will bring up a menu from which you can ‘Add ‘JUnit 5.3’ to classpath’:
This should then bring up another dialog asking you if you want to download the jars from Maven. You do, but I also recommend checking the box specifying where to put the .jar files- the default location is in a ‘lib’ directory in the project directory. IntelliJ will then download the 4 jar files, put them in the newly created lib directory and add those jar files as a dependency called ‘JUnit 5.3’, which should be exactly what you want. This ensures that, when you package up the project and submit it, the JUnit libraries are packaged with it and will work out of the box without any further effort.
If IntelliJ reports that it is unable to resolve symbols related to JUnit 5.3, the marker will do the following:
• Download the four jars needed by JUnit 5.3 as described above
• Add them to the project dependencies (Project Structure Modules Dependencies)
• Mark the assignment
No marks will be lost in the Deployment category if this is all the marker needs to do to get the unit tests working.
JavaFX
JavaFX is optional, and mostly just available as a GUI choice for students that are either already familiar with JavaFX or are interested in experimenting with it. If in doubt we still recommend that you use Swing given the large amount of material and the fact that it is available within the JDK and does not require external libraries.
When you create a new project in IntelliJ you can choose to create a JavaFX project, but this is not necessary. What is important is that you download JavaFX and set up your project to point to it.
We recommend following the openjfx.io guide ‘Getting Started with JavaFX’, specifically ‘JavaFX and IntelliJ’ found here:
https://openjfx.io/openjfx-docs/#IDE-Intellij
There is no need to set the language level or project SDK to JDK 12- we are still using JDK 11 in this subject, and JavaFX 12 supports this just fine. The main steps that need to be taken are:
• You need to download the JavaFX SDK for your platform and extract it somewhere
• You need to configure your project to see JavaFX as a library
• You need to add –module-path “D:\cab302\javafx-sdk-12\lib” –add-
modules javafx.controls,javafx.fxml or something similar (depending on where you installed JavaFX) to your project’s run configuration.
Now, because JavaFX is both a) very large, and b) including platform-specific native code libraries we do not want to / can’t just include the libraries in our project. Thus, for JavaFX projects, markers will be instructed to do the following:
• The marker will install the latest version of JavaFX 12, if it is not already installed.
• If IntelliJ reports that it cannot resolve symbols associated with JavaFX (import javafx etc.),
the marker will go into Project StructureModulesDependencies, then add the lib
directory from JavaFX to the dependencies list
• The marker will modify the project run configuration and paste in the above –module-path
line (modified to match the location of JavaFX on the marker’s system), overwriting anything that was there previously.
• The marker will then mark the assignment.
No marks will be lost in the Deployment category if this is all the marker needs to do to get the JavaFX assignment working.