From 1c580b0165e73492e7cf23a88f548056e07e2559 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Mon, 16 Dec 2024 11:38:01 +0000 Subject: [PATCH] Prefer Guice injection in sample (#628) * Prefer Guice injection in sample --- .../maven-resolver-demo-maven-plugin/pom.xml | 5 +++++ .../examples/maven/ResolveArtifactMojo.java | 18 ++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/maven-resolver-demos/maven-resolver-demo-maven-plugin/pom.xml b/maven-resolver-demos/maven-resolver-demo-maven-plugin/pom.xml index 5c3bfb19b..8097bd3da 100644 --- a/maven-resolver-demos/maven-resolver-demo-maven-plugin/pom.xml +++ b/maven-resolver-demos/maven-resolver-demo-maven-plugin/pom.xml @@ -72,6 +72,11 @@ slf4j-api provided + + javax.inject + javax.inject + compile + diff --git a/maven-resolver-demos/maven-resolver-demo-maven-plugin/src/main/java/org/apache/maven/resolver/examples/maven/ResolveArtifactMojo.java b/maven-resolver-demos/maven-resolver-demo-maven-plugin/src/main/java/org/apache/maven/resolver/examples/maven/ResolveArtifactMojo.java index 3d157be56..b1053fe44 100644 --- a/maven-resolver-demos/maven-resolver-demo-maven-plugin/src/main/java/org/apache/maven/resolver/examples/maven/ResolveArtifactMojo.java +++ b/maven-resolver-demos/maven-resolver-demo-maven-plugin/src/main/java/org/apache/maven/resolver/examples/maven/ResolveArtifactMojo.java @@ -18,12 +18,13 @@ */ package org.apache.maven.resolver.examples.maven; +import javax.inject.Inject; + import java.util.List; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; -import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.eclipse.aether.RepositorySystem; @@ -43,11 +44,6 @@ @Mojo(name = "resolve-artifact", threadSafe = true) public class ResolveArtifactMojo extends AbstractMojo { private static final Logger LOGGER = LoggerFactory.getLogger(ResolveArtifactMojo.class); - /** - * The entry point to Maven Artifact Resolver, i.e. the component doing all the work. - */ - @Component - private RepositorySystem repoSystem; /** * The current repository/network configuration of Maven. @@ -67,6 +63,16 @@ public class ResolveArtifactMojo extends AbstractMojo { @Parameter(property = "resolver.artifactCoords", readonly = true) private String artifactCoords; + /** + * The entry point to Maven Artifact Resolver; that is, the component doing all the work. + */ + private final RepositorySystem repoSystem; + + @Inject + public ResolveArtifactMojo(RepositorySystem repoSystem) { + this.repoSystem = repoSystem; + } + /** * The actual execution of the mojo. */