Resolve Maven POM

Last modified by Andreea Popescu on 2014/08/22 07:36

cogShows how to access any Maven POM data from an XWiki page
Developed by

Vincent Massol

0 Votes
LicenseGNU Lesser General Public License 2.1

XWiki 3.4+

Table of contents


Have you ever tried to access Maven POM data in your Java application? If so you know it's a real pain to try using the Maven 3 in embedded mode. A little bit better is to use Aether but you'll face several issues too: lack of documentation and the fact that Aether only provides access to a very small subset of the Maven POM information...

So here comes the XWiki Extension Module to save the day!

If you wish instead to use XWiki as a Java Library instead and resolve a Maven POM from Java, you could check Vincent's maven-pom-resolution example on GitHub.

Here's a quick example in Velocity to get access to the data from the XWiki Platform v3.4 POM:

#set ($model = $services.extension.resolve("org.xwiki.platform:xwiki-platform", "3.4").getProperty("maven.Model"))
Name: $
Description: $model.description
Organization name: $

This will display:


Now this will look for the Maven Artifact in all configured XWiki Extension Repositories.

You can look in any given repository directory with some Groovy code, just a little bit more complex:

import com.xpn.xwiki.web.Utils
import org.xwiki.extension.repository.*
import org.xwiki.extension.*

def repositoryFactory =  Utils.getComponent(ExtensionRepositoryFactory, "maven")
def repositoryId = new ExtensionRepositoryId("maven-xwiki", "maven", new URI(""))
def repository = repositoryFactory.createRepository(repositoryId)
def extension = repository.resolve(new ExtensionId("org.xwiki.commons:xwiki-commons-component-default", "3.4"))
def model = extension.getProperty("maven.Model")

println "Name: ${}"

model.getDependencies().each() {
  println "* ${it.groupId}:${it.artifactId}:${it.version}"

This snippet will generate:


Last, if you wish to just reuse an Extension Repository already defined in XWiki's configuration, you can use:

import com.xpn.xwiki.web.Utils
import org.xwiki.extension.repository.*
import org.xwiki.extension.*

def repositoryManager = Utils.getComponent(ExtensionRepositoryManager.class)
def repository = repositoryManager.getRepository("maven-xwiki")

def extension = repository.resolve(new ExtensionId("org.xwiki.platform:xwiki-platform", "3.4"))
def model = extension.getProperty("maven.Model")


It's that simple! emoticon_smile

Tags: maven
Created by Vincent Massol on 2012/02/01 19:28

Download XWiki

Get Connected