To get a Maven project set up on Code Ocean, you'll need to edit the Dockerfile
so that dependencies get installed during build time rather than run time. While this might sound daunting if you're unfamiliar with Docker, the good news is that all you need to do is follow the steps outlined below:
Prerequisite: project uploaded to the
code
folder (make sure to separate any data and place it in thedata
folder).In the environment editor, add
maven
as an apt-get dependency.Move
pom.xml
to theenvironment
folder by dragging and dropping.Click
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 (step 4), and then instruct it to build the the project in offline mode (step 5).
The fly in the ointment is Maven doesn't fetch plugin dependencies (see this long-standing Maven bug) and so 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, thereby breaking the build and rendering the results non-reproducible.