To get a Maven project set up on Code Ocean, the Dockerfile
must be edited so that dependencies get installed during build time rather than run time. If you're unfamiliar with Docker, follow the steps outlined below:
Prerequisite: the project must be uploaded to the
code
folder ensure that any data is separate and placed in thedata
folder.In the environment editor, add
maven
as an apt-get dependency.Move
pom.xml
to theenvironment
folder by dragging and dropping itClick
Dockerfile
, unlock it for editing, and add the following lines at the end:
โCOPY pom.xml /tmp
RUN cd /tmp && mvn package && rm -rf /tmp/targetMake sure
code/run
, or your master script, has the following lines before the actual commands to run your code:
โmv /tmp/pom.xml .
mvn package --offline
What this will do is instruct Maven to download all dependencies when the image is being built in step 4, and then instruct it to build the project in offline mode, step 5.
Note: Maven doesn't fetch plugin dependencies (see this long-standing Maven bug). Even though the project dependencies are preserved in the image, there's a chance that eventually one of the plugin dependencies will disappear from Maven Central, breaking the build and rendering the results non-reproducible.