The Export Maven Plugin is an Apache Maven plugin designed for exporting an entire Maven project into a .zip file. It respects the .gitignore settings and, regardless of .gitignore, always omits the build directory (target).
Typically, archiving a project involves the following command:
git archive -o export.zip HEADHowever, in teaching environments, particularly when instructing large groups in Java, it's not always feasible to assume that Git is installed on all systems. In scenarios where Git is not part of the course curriculum, and lab/homework submissions are required in .zip format, it's important to ensure that students' submissions do not include unwanted files, such as those in the build folder or IDE-specific directories.
Since students are expected to use Maven and create their projects via homework-quickstart archetype, this simple plugin enables students to automatically export their projects in the required format without including unwanted files.
To use the plugin, insert the following configuration into the plugins section of your pom.xml:
<plugin>
<groupId>org.atp-fivt</groupId>
<artifactId>export-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<zipFileName>Name_Surname.zip</zipFileName>
</configuration>
</plugin>The zipFileName parameter allows you to specify the desired name for the zip file. By default, the file name is set to export.zip.
To run the plugin, execute:
mvn export:exportThe resulting .zip file will be located in the target directory.
This plugin leverages the jGit library to compile a list of all files in the project, adhering to the rules specified in .gitignore files. Importantly, the functionality of this plugin does not require Git to be installed on the target machine. This is particularly beneficial in educational settings or environments where Git installation cannot be assumed. By using jGit, the plugin operates independently of the local Git installation.
If you are a teacher preparing a homework/lab template and you don't want to include full solutions in the exported archive, you can enable the stripMarked flag:
<plugin>
<groupId>org.atp-fivt</groupId>
<artifactId>export-maven-plugin</artifactId>
<version>...</version>
<configuration>
<zipFileName>assignment_template.zip</zipFileName>
<stripMarked>true</stripMarked>
</configuration>
</plugin>When stripMarked is set to true, the plugin removes code blocks in Java sources that are wrapped with special markers and thus keeps only the assignment skeleton in the exported .zip. Use the following markers in Java files:
//[[
// implementation that should NOT be included into the student template
//]]Note: when exporting with stripMarked=true, the plugin also removes the <stripMarked>true</stripMarked> line from the exported pom.xml to avoid leaking the teacher-only setting into the student project.