我已经编写了Maven插件的一部分,但是它不能作为插件运行。它可以访问SCM或任何pom.xml,只是一个工件存储库和一些Maven坐标。它的目的是获取Maven坐标并打印出它们的依赖项(对它们执行一些报告)。要做到这一点,它需要通过编程访问(例如):
通常您已经将其注入到一个mojo中,但它不是一个mojo,不能以这样的方式运行(因为我没有pom.xml)。
我的代码对我没有帮助,例如AbstractMojoTestCase需要一个pom.xml,这是我没有的。
我想要一些代码,比如..。
DefaultPlexusContainer container = new DefaultPlexusContainer();
Context context = container.getContext();
context.put("plexus", new DefaultPlexusContainer());
container.initialize();
container.start();
MavenProjectBuilder mavenProjectBuilder = (MavenProjectBuilder) container.lookup(MavenProjectBuilder.ROLE);
DependencyGraphBuilder dependencyGraphBuilder = (DependencyGraphBuilder) container.lookup(DependencyGraphBuilder.class.getName());
MavenProject project = mavenProjectBuilder.buildFromRepository(artifact, remoteArtifactRepositories, localRepository);
// do stuff with dependencies但有东西不见了。帮助!
发布于 2013-02-08 13:41:30
看看它是如何实现https://github.com/jenkinsci/lib-jenkins-maven-embedder的(我们在jenkins中使用它来实现类似的目的)
https://stackoverflow.com/questions/14771567
复制相似问题