class OpearPackageMojo extends AbstractCommonMojo {

    Artifact attachArtifact(final @NotNull File finalFile) {
        final Artifact projectArtifact = this.project.getArtifact();
        final ArtifactHandler opearHandler = this.artifactHandlerManager.getArtifactHandler(OPEAR);
        if (OPEAR.equals(project.getPackaging())) {
            // set project artifact
            projectArtifact.setFile(finalFile);
            projectArtifact.setArtifactHandler(opearHandler);
            return projectArtifact;
        } else {
            // attach artifact
            Artifact attachment = new DefaultArtifact(
                    project.getGroupId(),
                    project.getArtifactId(),
                    project.getVersion(),
                    null,
                    OPEAR,
                    null,
                    opearHandler);
            attachment.setFile(finalFile);
            project.addAttachedArtifact(attachment);
            return attachment;
        }
    }

}