MavenProject:获取可用于我的插件的可用类 [英] MavenProject: Get the available classes for use on my plugin

查看:347
本文介绍了MavenProject:获取可用于我的插件的可用类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在按此处.我试图弄清楚如何检索源根,以便弄清楚拥有的Java类,以便我的Mojo可以使用它们.

I'm loading a Maven project as described here. I'm trying to figure out how I can retrieve the source roots so I can figure out the Java classes I have so my Mojo can use them.

我在那里尝试了几种方法,例如没有运气的getResources或getScriptSources.有什么主意吗?

I tried a couple of the methods in there, like getResources or getScriptSources without luck. Any idea?

提前谢谢!

有人要求我详细说明我要尝试做的事情,所以这里是:

I was asked to elaborate a little bit in what I'm attempting to do, so here it is:

我正在开发的插件将获取项目中的源,并从中创建测试用例.除非进行了配置,否则我想为所有类生成测试,为此,我需要以某种方式找出我的源代码,以便可以正确地进行配置.

The plugin I'm developing will take the sources in the project and create test cases from those. Unless configured, I want to generate tests for all the classes, and for that, I need to somehow figure out where are my sources so I can configure properly.

希望有帮助.

这是存储库.我计划以后再发布它,但我按要求提供了源代码.

Here's the repository. I planned on publishing it later but I provided source as requested.

推荐答案

您是否已阅读插件开发人员文档?

该页面将链接到插件食谱,该链接将链接到 Mojo开发人员手册,其中具有

That page will link to Plugins Cookbook which links to Mojo Developer Cookbook which has The maven project, or the effective pom. and gives you access to org.apache.maven.project.MavenProject object via

/** @parameter default-value="${project}" */
private org.apache.maven.project.MavenProject mavenProject;

或者通过Java 5注释

Alternatively via Java 5 annotations

@Component
MavenProject project;

您可以调用 getCompileSourceRoots() 以获得要用于编译的目录的列表.

You can call getCompileSourceRoots() to get a list of the directories that will be used for compilation.

您还需要阅读更多有关如何设置包含/排除的信息.您可以使用其他插件作为执行此操作的示例,例如 maven-compiler-plugin

You will also need to do more reading about how to setup inclusion/exclusions. You can use other plugins as examples of how to do this, e.g. maven-compiler-plugin

如果要使用注释,非常非常重要,以确保按照

If you want to use annotations, it is very important to make sure your pom is configured as per using annotations and that you use annotations at the class level as well. Mixing javadoc annotations might not work.

这篇关于MavenProject:获取可用于我的插件的可用类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆