Skip to content

Commit

Permalink
use @component instead of @parameter when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
hboutemy committed Mar 23, 2024
1 parent d8fecbc commit 6f9c3d9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Expand Up @@ -23,6 +23,7 @@

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;

Expand All @@ -36,7 +37,7 @@ public abstract class AbstractGeneratorMojo extends AbstractMojo {
/**
* The project currently being built.
*/
@Parameter(defaultValue = "${project}", readonly = true)
@Component
protected MavenProject project;

/**
Expand Down
Expand Up @@ -29,6 +29,7 @@
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.artifact.resolver.filter.IncludesArtifactFilter;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.descriptor.InvalidPluginDescriptorException;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
Expand All @@ -48,7 +49,6 @@
import org.apache.maven.tools.plugin.scanner.MojoScanner;
import org.codehaus.plexus.component.repository.ComponentDependency;
import org.codehaus.plexus.util.ReaderFactory;
import org.eclipse.aether.RepositorySystemSession;
import org.sonatype.plexus.build.incremental.BuildContext;

/**
Expand Down Expand Up @@ -226,11 +226,12 @@ public class DescriptorGeneratorMojo extends AbstractGeneratorMojo {
*
* @since 3.7.0
*/
@Parameter(defaultValue = "${settings}", readonly = true, required = true)
@Component
private Settings settings;

@Parameter(defaultValue = "${repositorySystemSession}", readonly = true, required = true)
private RepositorySystemSession repoSession;
@Component
private MavenSession mavenSession;

/**
* The required Java version to set in the plugin descriptor. This is evaluated by Maven 4 and ignored by earlier
* Maven versions. Can be either one of the following formats:
Expand Down Expand Up @@ -346,7 +347,7 @@ public void generate() throws MojoExecutionException {
request.setEncoding(encoding);
request.setSkipErrorNoDescriptorsFound(skipErrorNoDescriptorsFound);
request.setDependencies(filterMojoDependencies());
request.setRepoSession(repoSession);
request.setRepoSession(mavenSession.getRepositorySession());
request.setInternalJavadocBaseUrl(internalJavadocBaseUrl);
request.setInternalJavadocVersion(internalJavadocVersion);
request.setExternalJavadocBaseUrls(externalJavadocBaseUrls);
Expand Down
Expand Up @@ -25,6 +25,7 @@
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
Expand All @@ -51,7 +52,7 @@ public class AddPluginArtifactMetadataMojo extends AbstractMojo {
/**
* The project artifact, which should have the <code>latest</code> metadata added to it.
*/
@Parameter(defaultValue = "${project}", readonly = true)
@Component
private MavenProject project;

/**
Expand Down

0 comments on commit 6f9c3d9

Please sign in to comment.