class OpearPlanMojo extends AbstractCommonMojo implements MojoWithPlanParams {

    @Override
    public void execute() throws MojoFailureException {
        planFile.getParentFile().mkdirs();

        final JsonWriterFactory writerFactory =
                Json.createWriterFactory(Collections.singletonMap(JsonGenerator.PRETTY_PRINTING, true));
        ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
        try (OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream(planFile), StandardCharsets.UTF_8);
             JsonWriter writer = writerFactory.createWriter(osw)) {
            Thread.currentThread().setContextClassLoader(createContainerClassLoader());
            OakpalPlan plan = buildPlan();
            writer.writeObject(plan.toJson());
        } catch (IOException e) {
            throw new MojoFailureException("Failed to write plan json to file " + planFile.getAbsolutePath(), e);
        } finally {
            Thread.currentThread().setContextClassLoader(oldCl);
        }
    }

}