Comment obtenir l'emplacement du référentiel local (URI) à partir du plugin Maven 3.x? P>
4 Réponses :
Utilisez AETher comme décrit dans Ce blog post .
LocalRepository localRepo = repoSession.getLocalRepository();
@Dmytrochyzhykov aucune idée, vous devriez poser une question distincte
@san Patrick Floyd a fourni une réponse solide.
Cette solution ne nécessite pas l'injection des propriétés dans vos champs d'instance. P>
@Override public void execute() throws MojoExecutionException { MavenProject project=(MavenProject)getPluginContext().get("project"); Set<Artifact> arts=project.getDependencyArtifacts(); Set<String> localRepoSet = new HashSet<>(); for (Artifact art : arts) { if (art.getScope().equals(Artifact.SCOPE_COMPILE)) { Path path = Paths.get(art.getFile().getAbsolutePath()); String removal = art.getGroupId().replace(".", "/") + "/" + art.getArtifactId() + "/" + art.getVersion(); String localRepo = path.getParent().toAbsolutePath().toString().replace(removal, ""); localRepoSet.add(localRepo); } } }
Vous pouvez simplement obtenir l'emplacement local du référentiel à partir des paramètres:
@Parameter( defaultValue = "${settings}", readonly = true ) private Settings settings; public void execute() throws MojoExecutionException { final File localRepository = new File(settings.getLocalRepository()); ... }
Celui-ci a travaillé pour moi à Maven v3.6.0: