The javac compiler starts behaving differently if it finds module-info.class file from a previous compilation in the target directory: it tries to resolve the modules, but it fails since the module jars are on the classpath, not the modulepath:
error: module not found: org.apache.logging.log4j
Therefore we need to use a clean execution before each compile execution that will delete that file.