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:

  1. Prerequisite: project uploaded to the code folder (make sure to separate any data and place it in the data folder).

  2. In the environment editor, add maven as an apt-get dependency.

  3. Move pom.xml to the environment folder by dragging and dropping.

  4. 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/target

  5. Make 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.


Did this answer your question?