Developer
DevOps
System Administrator
Jahia 8.1
Jahia 8.2
How to list the maven repositories configured in Jahia using the provisioning API?
Question
How to list the maven repositories configured in Jahia using the provisioning API?
Answer
The Maven configuration is persisted in the file JAHIA_HOME/digital-factory-data/karaf/etc/org.ops4j.pax.url.mvn.cfg. There are two properties related to the repositories:
# Comma separated list of repositories scanned when resolving an artifact.
# list of repositories searched in the first place, should contain
# ${runtime.home}/${karaf.default.repository}.
# if "org.ops4j.pax.url.mvn.localRepository" is defined and it's not
# ~/.m2/repository, it's recommended (at least for dev purposes) to add
# ~/.m2/repository to defaultRepositories
# each of these repositories is checked by aether as "local repository". if
# artifact isn't found, "repositories" are searched next
#
# Those repositories will be checked before iterating through the
# below list of repositories and even before the local repository
# A repository url can be appended with zero or more of the following flags:
# @snapshots : the repository contains snaphots
# @noreleases : the repository does not contain any released artifacts
#
# The following property value will add the system folder as a repo.
#
org.ops4j.pax.url.mvn.defaultRepositories=\
${karaf.home.uri}${karaf.default.repository}@id=system.repository@snapshots, \
${karaf.data.uri}kar@id=kar.repository@multi@snapshots, \
${karaf.base.uri}${karaf.default.repository}@id=child.system.repository@snapshots
# Comma separated list of repositories scanned when resolving an artifact.
# list of repositories searched after resolution fails for "defaultRepositories"
# These are true remote repositories accessed using maven/aether/wagon
# mechanisms. If any repository contains required artifact, it is then written
# to "localRepository"
#
# if this list is _prepended_ with '+' sign, all repositories from active
# profiles defined in effective settings.xml file will be _appended_ to this
# list
# The default list includes the following repositories:
# https://repo1.maven.org/maven2@id=central
# https://repository.apache.org/content/groups/snapshots-group@id=apache@snapshots@noreleases
# https://oss.sonatype.org/content/repositories/snapshots@id=sonatype.snapshots.deploy@snapshots@noreleases
# https://oss.sonatype.org/content/repositories/ops4j-snapshots@id=ops4j.sonatype.snapshots.deploy@snapshots@noreleases
# A repository url can be appended with zero or more of the following flags:
# @snapshots : the repository contains snapshots
# @noreleases : the repository does not contain any released artifacts
# @id=repository.id : the id for the repository, just like in the
# settings.xml this is optional but recommended
#
org.ops4j.pax.url.mvn.repositories= \
https://devtools.jahia.com/nexus/content/groups/public@id=jahia-public@snapshots, \
https://repo1.maven.org/maven2@id=central, \
https://oss.sonatype.org/content/repositories/ops4j-snapshots@id=ops4j.sonatype.snapshots.deploy@snapshots@noreleases
The provisioning API hasn't a specific command to list the repositories but it allows the execution of a groovy script.
Here are the steps to follow:
- Create the following Groovy script list-maven-repositories.groovy:
import org.jahia.osgi.BundleUtils; log.info("START - List maven repositories"); def configService = BundleUtils.getOsgiService("org.jahia.bundles.config.OsgiConfigService"); def settings = configService.getConfig("org.ops4j.pax.url.mvn"); def values = settings.getValues(); log.info("Maven repositories:"); for(def value: values.getProperty("org.ops4j.pax.url.mvn.repositories").split("[, ]+")){ log.info(value); } log.info("Default repositories:"); for(def value: values.getProperty("org.ops4j.pax.url.mvn.defaultRepositories").split("[, ]+")){ log.info(value); } log.info("End - List maven repositories")
- Create the following YAML manifest my-manifest.yaml:
- executeScript: "list-maven-repositories.groovy"
- Execute the following curl command:
curl -v -u USERNAME:PASSWORD -X POST JAHIA_URL/modules/api/provisioning --form script="@my-manifest.yaml;type=text/yaml" --form file="@list-maven-repositories.groovy"
- Check the logs