14.5. Configuring Maven Proxies and HTTP Proxies through settings.xml
Overview
You can optionally configure the Maven proxy using a standard Maven
settings.xml
file. For example, this approach is particularly convenient in a development environment, because it makes it possible to store your build time settings and your run time settings in one place.
The Maven
settings.xml
approach is not used by default. You must explicitly enable it.
Adding a remote Maven repository
A default
settings.xml
file is provided for you in InstallDir/etc/maven-settings.xml
. To add a new remote Maven repository to the InstallDir/etc/maven-settings.xml
file, open the maven-settings.xml
file in a text editor and add a new repository
XML element. For example, to create an entry for the Red Hat GA public Maven repository, add a repository
element as shown:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> ... <!-- If org.ops4j.pax.url.mvn.repositories property is _prepended_ with '+' sign, repositories from all active profiles will be _appended_ to the list of searched remote repositories --> <profiles> <profile> <id>default</id> <repositories> <repository> <id>redhat-ga-repository</id> <url>https://maven.repository.redhat.com/ga</url> </repository> </repositories> </profile> </profiles> <activeProfiles> <activeProfile>default</activeProfile> </activeProfiles> </settings>
Important
Do not forget to activate your profile, by adding an
activeProfile
element that references the profile ID (in this example, the profile ID is default
).
Enabling the settings.xml configuration approach
To configure Fabric to read its Maven configuration from a Maven
settings.xml
file, perform the following steps:
- Configure the Maven repositories you need in the
InstallDir/etc/maven-settings.xml
file (see the section called “Adding a remote Maven repository”). - Copy the Maven repositories from the
io.fabric8.agent/org.ops4j.pax.url.mvn.settings
property into themaven-settings.xml
file (normally, you need to preserve access to these repositories). To see the list of repositories from theio.fabric8.agent/org.ops4j.pax.url.mvn.settings
property in thedefault
profile, enter the following Fabric8 command:JBossFuse:karaf@root> profile-display default
Follow the instructions in the section called “Adding a remote Maven repository” to add these repositories set inio.fabric8.agent/org.ops4j.pax.url.mvn.settings
to themaven-settings.xml
file (if they are not already present). - (Optional) If you want to combine the list of repositories appearing in the
maven-settings.xml
file with the list of repositories from theio.fabric8.maven/io.fabric8.maven.repositories
property, prepend a+
sign to the list of repositories inio.fabric8.maven.repositories
. For example:io.fabric8.maven.repositories=+http://repo1.maven.org/maven2@id=maven.central.repo,https://maven.repository.redhat.com/ga@id=redhat.ga.repo,https://maven.repository.redhat.com/earlyaccess/all@id=redhat.ea.repo,https://repository.jboss.org/nexus/content/groupsea@id=fuseearlyaccess
- Delete the
org.ops4j.pax.url.mvn.repositories
property setting from theio.fabric8.agent
PID in thedefault
profile, using the following console command:profile-edit --delete --pid io.fabric8.agent/org.ops4j.pax.url.mvn.repositories default
When the repositories setting is absent, Fabric implicitly switches to themaven-settings.xml
configuration approach.NoteBy default, this step simultaneously clears both the repository list used by the Fabric8 agent and the repository list used by the Maven proxy server (because the Maven proxy's repository list normally references the Fabric8 agent's repository list).
Changing the default location of Maven settings.xml
Fabric is pre-configured to use the
InstallDir/etc/maven-settings.xml
file. That is, the following settings are configured by default:
io.fabric8.maven/io.fabric8.maven.settings = ${karaf.etc}/maven-settings.xml io.fabric8.agent/org.ops4j.pax.url.mvn.settings = ${karaf.etc}/maven-settings.xml
If you need to customize the location of your Maven
settings.xml
file, edit the value of these properties in the default
profile.
Configuring an HTTP proxy
To configure an HTTP proxy (which will be used when connecting to remote Maven repositories), open the
etc/maven-settings.xml
file in a text editor and add a new proxy
XML element as a child of the proxies
XML element. The definition of the proxy follows the standard Maven syntax. For example, to create a proxy for the HTTP (insecure) protocol with host, 127.0.0.1
, and port, 3128
, add a proxy
element as follows:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> ... <!-- This is the place to configure http proxies used by Aether. If there's no proxy for "https" protocol, proxy for "http" will be used when accessing remote repository --> <proxies> <!-- <proxy> <id>proxy</id> <host>127.0.0.1</host> <port>3128</port> <protocol>http</protocol> <username></username> <password></password> <nonProxyHosts>127.0.0.*|ensemble1|ensemble2|ensemble3</nonProxyHosts> </proxy> --> </proxies> ... </settings>
You must remember to add the ensemble hosts (where the Maven proxy servers are running) to the list of HTTP non-proxy hosts in the
nonProxyHosts
element. This ensures that the Fabric8 agents do not attempt to connect to the Maven proxies through the HTTP proxy, but make a direct connection instead. In the preceding example, the ensemble host names are ensemble1
, ensemble2
, and ensemble3
.
By default, HTTPS connections use the same proxy settings as the HTTP protocol. If you need separate configuration for HTTPS, you can optionally add another
proxy
element configured with the https
protocol.
Reference
For a detailed description of the syntax of the Maven
settings.xml
file, see the Maven Settings Reference. But please note that not all of the features documented there are necessarily supported by Fabric.