public File buildArchive(ImageConfiguration imageConfiguration, BuildContext buildContext, String archivePath)
            throws MojoExecutionException {
        String imageName = imageConfiguration.getName();
        ImageName.validate(imageName);
        BuildImageConfiguration buildConfig = imageConfiguration.getBuildConfiguration();
        MojoParameters params = buildContext.getMojoParameters();

        if (buildConfig.getDockerArchive() != null) {
            return buildConfig.getAbsoluteDockerTarPath(params);
        }
        long time = System.currentTimeMillis();

        File dockerArchive = archiveService.createArchive(imageName, buildConfig, params, log);
        log.info("%s: Created %s in %s", imageConfiguration.getDescription(), dockerArchive.getName(), EnvUtil.formatDurationTill(time));

        // Copy created tarball to directory if specified
        try {
            copyDockerArchive(imageConfiguration, dockerArchive, archivePath);
        } catch (IOException exception) {
            throw new MojoExecutionException("Error while copying created tar to specified buildArchive path: " + archivePath,
                    exception);
        }
        return dockerArchive;
    }
Create docker archive for building image

@param imageConfiguration image configuration
@param buildContext       docker build context
@param archivePath        build archive only flag, it can have values TRUE or FALSE and also
                          it can hold path to archive where it might get copied over
@return tarball for docker image
@throws MojoExecutionException in case any exception comes during building tarball
src/main/java/io/fabric8/maven/docker/service/BuildService.java