Can I use Maven repository manager outside of Maven?

落花浮王杯 提交于 2019-12-25 01:27:18

问题


I already asked in Maven User List, let me duplicate here.

I'm trying to create an application that will download and use Maven artifacts outside of Maven. I think that in this case the smartest way would be to use Maven already existing classes. Can anyone help me with a hint where to look for?

Would be nice to make it working this way:

Repository rep = new Repository("~/.m2"); 
Artifact artifact = new Artifact("com.example", "foo", "1.0"); 
String path = rep.resolve(artifact); 
assert path.equals("~/.m2/repository/com/example/foo/1.0/foo.jar"); 

I'm using Maven 3.


回答1:


Aether does exactly what I need.

edit: A few weeks ago I created an open source tool that simplifies the interaction with Aether: jcabi-aether. Now it is as simple as (in maven plugin):

File repo = this.session.getLocalRepository().getBasedir();
Collection<Artifact> deps = new Aether(this.getProject(), repo).resolve(
  new DefaultArtifact("junit", "junit-dep", "", "jar", "4.10"),
  JavaScopes.RUNTIME
);



回答2:


Have you taken a look at ivy to see if it fits your needs?



来源:https://stackoverflow.com/questions/5296271/can-i-use-maven-repository-manager-outside-of-maven

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!