Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update document to use Guice constructor injection #345

Merged
merged 2 commits into from
Dec 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions maven-plugin-tools-annotations/src/site/apt/index.apt
Original file line number Diff line number Diff line change
Expand Up @@ -90,28 +90,6 @@ public class MyMojo
required = <false|true> )
private String parameter;

@Component( role = MyComponentExtension.class,
hint = "..." )
private MyComponent component;

// pseudo-parameters (marked read-only) permitting injection of Maven build context objects
// sample objects taken from Maven API through PluginParameterExpressionEvaluator
// https://maven.apache.org/ref/current/maven-core/apidocs/org/apache/maven/plugin/PluginParameterExpressionEvaluator.html
// plugins targetting Maven 3.2.5+ (after MNG-5695) should not use these pseudo-parameters any more,
// but @Component and Maven APIs to get better compiler-time checks

// @Parameter( defaultValue = "${session}", readonly = true )
@Component // since Maven 3.2.5, thanks to MNG-5695
private MavenSession session;

// @Parameter( defaultValue = "${project}", readonly = true )
@Component // since Maven 3.2.5, thanks to MNG-5695
private MavenProject project;

// @Parameter( defaultValue = "${mojoExecution}", readonly = true )
@Component // since Maven 3.2.5, thanks to MNG-5695
private MojoExecution mojoExecution;

@Parameter( defaultValue = "${reactorProjects}", readonly = true )
// prefer using session.getProjects()
private List<MavenProject> reactorProjects;
Expand All @@ -132,6 +110,28 @@ public class MyMojo
// prefer using project.getBuild().getDirectory()
private File target;

// pseudo-parameters (marked read-only) permitting injection of Maven build context objects
// sample objects taken from Maven API through PluginParameterExpressionEvaluator
// https://maven.apache.org/ref/current/maven-core/apidocs/org/apache/maven/plugin/PluginParameterExpressionEvaluator.html
// plugins targeting Maven 3.2.5+ (after MNG-5695) should not use these pseudo-parameters any more,
// but @Inject and Maven APIs to get better compiler-time checks

private final MyComponent component;

private final MavenSession session;

private final MavenProject project;

private final MojoExecution mojoExecution;

@Inject
public MyMojo(MyComponent component, MavenSession session, MavenProject project, MojoExecution mojoExecution) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Inject annotation missing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

this.component = component;
this.session = session;
this.project = project;
this.mojoExecution = mojoExecution;
}

/**
* @Parameter for methods can be used only with public setter methods
*/
Expand Down
Loading