Maven Eclipse-Aether: getLicence() method

孤者浪人 提交于 2019-12-13 05:14:27

问题


I'm developing a maven-plugin to check dependencies' licenses, similar to this one, but I can't found any API for that... what I would like to have is something like

String licence = artifact.getLicence();

mrice on that license-check plugin just try to find the .pom file of that artifact, read it, and try to find the <license></license>.

Do you know how can I do this?


回答1:


You need to use org.apache.maven.model.License. (See api docs for details).

Something like this:

try {
    Reader reader = new FileReader(pomXmlFile);
    Model model;
    try {
        final MavenXpp3Reader xpp3Reader = new MavenXpp3Reader();
        model = xpp3Reader.read(reader);
    } finally {
        reader.close();
    }
    List<License> licenses = model.getLicenses();
} catch (XmlPullParserException ex) {
    ex.printStackTrace();
} catch (IOException ex) {
    ex.printStackTrace();
}

*Note that many poms do not have a license.



来源:https://stackoverflow.com/questions/25937525/maven-eclipse-aether-getlicence-method

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