# 1 楼答案 您只需通过以下设置获取本地存储库位置: @Parameter( defaultValue = "${settings}", readonly = true ) private Settings settings; public void execute() throws MojoExecutionException { final File localRepository = new File(settings.getLocalRepository()); ... } 它在maven-3x中工作
# 2 楼答案 如this blog post所述使用乙醚 /** * The current repository/network configuration of Maven. * * @parameter default-value="${repositorySystemSession}" * @readonly */ private RepositorySystemSession repoSession; 现在通过^{}获得本地回购: LocalRepository localRepo = repoSession.getLocalRepository(); ^{}有一个^{}方法,这可能是您想要的
# 3 楼答案 这个在Maven v3中对我有效。6.0: @Parameter(defaultValue = "${localRepository}", readonly = true, required = true) private ArtifactRepository localRepository;
# 4 楼答案 @Sean Patrick Floyd提供了一个可靠的答案 此解决方案不需要将属性注入实例字段 @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); } } } 您可以获得所有直接依赖项的可能位置 在Maven 3中测试。X.X
# 1 楼答案
您只需通过以下设置获取本地存储库位置:
它在maven-3x中工作
# 2 楼答案
如this blog post所述使用乙醚
现在通过^{} 获得本地回购:
^{} 有一个^{} 方法,这可能是您想要的
# 3 楼答案
这个在Maven v3中对我有效。6.0:
# 4 楼答案
@Sean Patrick Floyd提供了一个可靠的答案
此解决方案不需要将属性注入实例字段
您可以获得所有直接依赖项的可能位置
在Maven 3中测试。X.X