Skip to content

Commit

Permalink
Update sample code to use Guice injection instead of Plexus (#627)
Browse files Browse the repository at this point in the history
  • Loading branch information
elharo authored Dec 15, 2024
1 parent 09471a6 commit 9e1685b
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/site/markdown/using-resolver-in-maven-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,37 +70,42 @@ import org.eclipse.aether.repository.RemoteRepository;
public class MyMojo extends AbstractMojo
{

/**
* The entry point to resolver (a.k.a. Aether), i.e. the component doing all the work.
*/
@Component
private RepositorySystem repoSystem;

/**
* The current repository/network configuration of Maven.
*/
@Parameter(defaultValue="${repositorySystemSession}", readonly = true)
private RepositorySystemSession repoSession;
private RepositorySystemSession repositorySystemSession;

/**
* The project's remote repositories to use for the resolution of project dependencies.
*/
@Parameter(defaultValue = "${project.remoteProjectRepositories}", readonly = true)
private List<RemoteRepository> projectRepos;
private List<RemoteRepository> remoteProjectRepositories;

/**
* The project's remote repositories to use for the resolution of plugins and their dependencies.
*/
@Parameter(defaultValue = "${project.remotePluginRepositories}", readonly = true)
private List<RemoteRepository> pluginRepos;
private List<RemoteRepository> remotePluginRepositories;


/**
* The entry point to the resolver (a.k.a. Aether); that is, the component doing all the work.
*/
private final RepositorySystem repositorySystem;

@Inject
public MyMojo(RepositorySystem repositorySystem) {
this.repositorySystem = repositorySystem;
}

// Your other mojo parameters and code here
...
}
```

Usually, you need only `projectRepos` or `pluginRepos` depending on the
nature of artifacts your plugin is dealing with, so the other plugin
Usually, you need only `remoteProjectRepositories` or `remotePluginRepositories`
depending on the nature of artifacts your plugin is dealing with. The other plugin
parameter would be superfluous in that case. But in general, the bits
shown above should give you all handles that you need to work with
shown above should give you all the handles that you need to work with
Aether from within a Maven plugin.

0 comments on commit 9e1685b

Please sign in to comment.