Search code examples
javamavenaether

Maven Eclipse-Aether: getLicence() method


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?


Solution

  • 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.