public void execute()

in src/main/java/org/apache/maven/plugins/deploy/DeployFileMojo.java [236:418]


    public void execute() throws MojoException {
        if (Boolean.parseBoolean(skip)
                || ("releases".equals(skip) && !session.isVersionSnapshot(version))
                || ("snapshots".equals(skip) && session.isVersionSnapshot(version))) {
            getLog().info("Skipping artifact deployment");
            return;
        }

        if (!Files.exists(file)) {
            String message = "The specified file '" + file + "' does not exist";
            getLog().error(message);
            throw new MojoException(message);
        }

        initProperties();

        RemoteRepository deploymentRepository =
                createDeploymentArtifactRepository(repositoryId, url.replace(File.separator, "/"));

        if (deploymentRepository.getProtocol().isEmpty()) {
            throw new MojoException("No transfer protocol found.");
        }

        Path deployedPom;
        if (pomFile != null) {
            deployedPom = pomFile;
            processModel(readModel(deployedPom));
        } else {
            deployedPom = readingPomFromJarFile();
        }

        if (groupId == null || artifactId == null || version == null || packaging == null) {
            throw new MojoException("The artifact information is incomplete: 'groupId', 'artifactId', "
                    + "'version' and 'packaging' are required.");
        }

        if (!isValidId(groupId) || !isValidId(artifactId) || !isValidVersion(version)) {
            throw new MojoException("The artifact information is not valid: uses invalid characters.");
        }

        failIfOffline();
        warnIfAffectedPackagingAndMaven(packaging);

        List<ProducedArtifact> deployables = new ArrayList<>();

        boolean isFilePom = classifier == null && "pom".equals(packaging);
        ProducedArtifact artifact = session.createProducedArtifact(
                groupId, artifactId, version, classifier, isFilePom ? "pom" : getExtension(file), packaging);

        if (file.equals(getLocalRepositoryFile(artifact))) {
            throw new MojoException("Cannot deploy artifact from the local repository: " + file);
        }

        ArtifactManager artifactManager = session.getService(ArtifactManager.class);
        artifactManager.setPath(artifact, file);
        deployables.add(artifact);

        ProducedArtifact pomArtifact = null;
        if (!isFilePom) {
            pomArtifact = session.createProducedArtifact(groupId, artifactId, version, "", "pom", null);
            if (deployedPom != null) {
                artifactManager.setPath(pomArtifact, deployedPom);
                deployables.add(pomArtifact);
            } else {
                deployedPom = generatePomFile();
                artifactManager.setPath(pomArtifact, deployedPom);
                if (generatePom) {
                    getLog().debug("Deploying generated POM");
                    deployables.add(pomArtifact);
                } else {
                    getLog().debug("Skipping deploying POM");
                }
            }
        }

        if (sources != null) {
            ProducedArtifact sourcesArtifact =
                    session.createProducedArtifact(groupId, artifactId, version, "sources", "jar", null);
            artifactManager.setPath(sourcesArtifact, sources);
            deployables.add(sourcesArtifact);
        }

        if (javadoc != null) {
            ProducedArtifact javadocArtifact =
                    session.createProducedArtifact(groupId, artifactId, version, "javadoc", "jar", null);
            artifactManager.setPath(javadocArtifact, javadoc);
            deployables.add(javadocArtifact);
        }

        if (files != null) {
            if (types == null) {
                throw new MojoException("You must specify 'types' if you specify 'files'");
            }
            if (classifiers == null) {
                throw new MojoException("You must specify 'classifiers' if you specify 'files'");
            }
            int filesLength = countCommas(files);
            int typesLength = countCommas(types);
            int classifiersLength = countCommas(classifiers);
            if (typesLength != filesLength) {
                throw new MojoException("You must specify the same number of entries in 'files' and "
                        + "'types' (respectively " + filesLength + " and " + typesLength + " entries )");
            }
            if (classifiersLength != filesLength) {
                throw new MojoException("You must specify the same number of entries in 'files' and "
                        + "'classifiers' (respectively " + filesLength + " and " + classifiersLength + " entries )");
            }
            int fi = 0;
            int ti = 0;
            int ci = 0;
            for (int i = 0; i <= filesLength; i++) {
                int nfi = files.indexOf(',', fi);
                if (nfi == -1) {
                    nfi = files.length();
                }
                int nti = types.indexOf(',', ti);
                if (nti == -1) {
                    nti = types.length();
                }
                int nci = classifiers.indexOf(',', ci);
                if (nci == -1) {
                    nci = classifiers.length();
                }
                Path file = Paths.get(files.substring(fi, nfi).replace("/", File.separator));
                if (!Files.isRegularFile(file)) {
                    // try relative to the project basedir just in case
                    file = Paths.get(files.substring(fi, nfi));
                }
                if (Files.isRegularFile(file)) {
                    String extension = getExtension(file);
                    String type = types.substring(ti, nti).trim();

                    ProducedArtifact deployable = session.createProducedArtifact(
                            artifact.getGroupId(),
                            artifact.getArtifactId(),
                            artifact.getVersion().asString(),
                            classifiers.substring(ci, nci).trim(),
                            extension,
                            type);
                    artifactManager.setPath(deployable, file);
                    deployables.add(deployable);
                } else {
                    throw new MojoException("Specified side artifact " + file + " does not exist");
                }
                fi = nfi + 1;
                ti = nti + 1;
                ci = nci + 1;
            }
        } else {
            if (types != null) {
                throw new MojoException("You must specify 'files' if you specify 'types'");
            }
            if (classifiers != null) {
                throw new MojoException("You must specify 'files' if you specify 'classifiers'");
            }
        }

        try {
            ArtifactDeployerRequest deployRequest = ArtifactDeployerRequest.builder()
                    .session(session)
                    .repository(deploymentRepository)
                    .artifacts(deployables)
                    .retryFailedDeploymentCount(Math.max(1, Math.min(10, getRetryFailedDeploymentCount())))
                    .build();

            getLog().info("Deploying artifacts " + deployables + " to repository " + deploymentRepository);
            ArtifactDeployer artifactDeployer = session.getService(ArtifactDeployer.class);
            artifactDeployer.deploy(deployRequest);
        } catch (ArtifactDeployerException e) {
            throw new MojoException(e.getMessage(), e);
        } finally {
            if (pomFile == null && deployedPom != null) {
                try {
                    Files.deleteIfExists(deployedPom);
                } catch (IOException e) {
                    // ignore
                }
                if (pomArtifact != null) {
                    artifactManager.setPath(pomArtifact, null);
                }
            }
        }
    }