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
codefolder ensure that any data is separate and placed in the
In the environment editor, add
mavenas an apt-get dependency.
environmentfolder by dragging and dropping it
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/target
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.