Skip to content

Commit

Permalink
Prefer Guice injection in sample (#628)
Browse files Browse the repository at this point in the history
* Prefer Guice injection in sample
  • Loading branch information
elharo authored Dec 16, 2024
1 parent 9e1685b commit 1c580b0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
5 changes: 5 additions & 0 deletions maven-resolver-demos/maven-resolver-demo-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@
<artifactId>slf4j-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand All @@ -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.
*/
Expand Down

0 comments on commit 1c580b0

Please sign in to comment.