From 2b81047a17e665e39261b797a4517b8f7282bbb1 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Fri, 13 Dec 2024 13:50:29 -0500 Subject: [PATCH 1/2] Prefer Guice injection in sample --- .../examples/maven/ResolveArtifactMojo.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) 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..a1a215d29 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 @@ -23,7 +23,6 @@ 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 +42,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 +61,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. */ From 68f96d6eef61549c52905d657d6370f057b61790 Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Sat, 14 Dec 2024 19:10:57 -0500 Subject: [PATCH 2/2] fix --- .../maven-resolver-demo-maven-plugin/pom.xml | 5 +++++ .../maven/resolver/examples/maven/ResolveArtifactMojo.java | 2 ++ 2 files changed, 7 insertions(+) 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 a1a215d29..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,6 +18,8 @@ */ package org.apache.maven.resolver.examples.maven; +import javax.inject.Inject; + import java.util.List; import org.apache.maven.plugin.AbstractMojo;