
org.glassfish.build.SetMainArtifactMojo Maven / Gradle / Ivy
/*
* Copyright (c) 2023 Eclipse Foundation and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package org.glassfish.build;
import java.io.File;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
/**
* Set project's main artifact.
*
* Useful in combination with the assembly-maven-plugin in a situation when it generates
* the one and only module's artifact without a classifier via a custom lifecycle,
* which results in complains of the maven install plugin about unset main artifact.
*/
@Mojo(name = "set-main-artifact", threadSafe = true)
public final class SetMainArtifactMojo extends AbstractMojo {
@Parameter(defaultValue = "${project}", readonly = true, required = true)
private MavenProject project;
/**
* The main artifact to be attached to the project as a main artifact.
*/
@Parameter(property = "file", required = true)
private File file;
/**
* The type of the artifact.
*/
@Parameter(property = "type", required = true)
private String type;
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
project.getArtifact().setFile(file);
getLog().info("Project main artifact file set to " + file.getAbsolutePath());
}
}