Using Amper
-
The subdirectory
tasks/task1_5in your repository contains yet another version of the ‘Hello World’ application. This is similar totask1_4, except that it uses Amper as the build system rather than Gradle.Take a few minutes to explore the files in
task1_5and its various subdirectories. -
Open the file
module.yamlin your editor and examine it. This is the Amper equivalent of Gradle’s build script. Notice that it is much smaller and simpler. All it does is declare that this is a JVM-based application, with dependencies on a couple of libraries that are needed to run the unit tests.To see what you can do with Amper, go to a terminal window, move into the
task1_5subdirectory and enter./amperThis command will work as above on Linux or macOS. If you see a ‘Permission denied’ error on these systems, you can fix this with
chmod u+x amperNote: If you are using Windows and your command prompt is provided by
cmd.exe, you’ll need to omit the leading./from the command to run it. If your command prompt is provided by Windows Powershell then you’ll need to use.\amper.batto run it. -
Enter the following command to run the tests:
./amper testAs with Gradle, it isn’t necessary to perform a separate compile step; Amper recognizes that this is a prerequisite to running tests, and it will compile the code first if needed.
The output generated by Amper is different from that produced by Gradle (and not quite as user-friendly, to be honest), but you should still be able to see details of which tests, if any, have failed.
-
Now try running the application, with
./amper runYou’ll see that Amper is a bit more verbose than Gradle with its logging. This can be distracting. You can suppress it using the
--log-level=offoption:./amper --log-level=off run -
Examine the contents of the
build/taskssubdirectory. You should see that this contains four subdirectories. Two of them are for the tests and two for the application itself. In each case, one subdirectory holds the individual.classfiles and the other holds a single JAR file containing those.classfiles. -
Finally, try packaging the application as a portable JAR file:
./amper packageThis will create a new subdirectory of
build/tasks, containing a single file namedtask1_5-jvm-executable.jar.You should be able run the application stored in the JAR file using
java -jarfollowed by the JAR filename. -
When you’re done, you can remove all of the build artifacts for the project with
./amper clean