Set up Maven so that Java workspaces can resolve dependencies from your internal Nexus or Artifactory server. .Prerequisites
About this task
- You are not running any Maven workspace.
- You know your user namespace, which is
<username>-devspaces where <username> is your OpenShift Dev Spaces username.
Procedure
- Create a Secret to store the TLS certificate:
kind: Secret
apiVersion: v1
metadata:
name: tls-cer
annotations:
controller.devfile.io/mount-path: /home/user/certs
controller.devfile.io/mount-as: file
labels:
controller.devfile.io/mount-to-devworkspace: 'true'
controller.devfile.io/watch-secret: 'true'
data:
tls.cer: >-
<Base64_encoded_content_of_public_cert>
where:
-
<Base64_encoded_content_of_public_cert>
-
The Base64-encoded content of your Maven artifact repository’s public TLS certificate, with line wrapping disabled.
- Apply the Secret to the
<username>-devspaces namespace:
$ oc apply -f tls-cer.yaml -n <username>-devspaces
- Create a ConfigMap for the
settings.xml file:
kind: ConfigMap
apiVersion: v1
metadata:
name: settings-xml
annotations:
controller.devfile.io/mount-as: subpath
controller.devfile.io/mount-path: /home/user/.m2
labels:
controller.devfile.io/mount-to-devworkspace: 'true'
controller.devfile.io/watch-configmap: 'true'
data:
settings.xml: |
<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 https://maven.apache.org/xsd/settings-1.0.0.xsd">
<localRepository/>
<interactiveMode/>
<offline/>
<pluginGroups/>
<servers/>
<mirrors>
<mirror>
<id>redhat-ga-mirror</id>
<name>Red Hat GA</name>
<url>https://<maven_artifact_repository_route>/repository/redhat-ga/</url>
<mirrorOf>redhat-ga</mirrorOf>
</mirror>
<mirror>
<id>maven-central-mirror</id>
<name>Maven Central</name>
<url>https://<maven_artifact_repository_route>/repository/maven-central/</url>
<mirrorOf>maven-central</mirrorOf>
</mirror>
<mirror>
<id>jboss-public-repository-mirror</id>
<name>JBoss Public Maven Repository</name>
<url>https://<maven_artifact_repository_route>/repository/jboss-public/</url>
<mirrorOf>jboss-public-repository</mirrorOf>
</mirror>
</mirrors>
<proxies/>
<profiles/>
<activeProfiles/>
</settings>
where:
-
<maven_artifact_repository_route>
-
The hostname and path of your internal Maven artifact repository.
- Optional: When using JBoss EAP-based devfiles, create a second
settings-xml ConfigMap with a different name and the /home/jboss/.m2 mount path. Use the same content as step 3.
- Create a ConfigMap for the TrustStore initialization script that matches your Java version:
For Java 8:
kind: ConfigMap
apiVersion: v1
metadata:
name: init-truststore
annotations:
controller.devfile.io/mount-as: subpath
controller.devfile.io/mount-path: /home/user/
labels:
controller.devfile.io/mount-to-devworkspace: 'true'
controller.devfile.io/watch-configmap: 'true'
data:
init-java8-truststore.sh: |
#!/usr/bin/env bash
keytool -importcert -noprompt -file /home/user/certs/tls.cer -trustcacerts -keystore ~/.java/current/jre/lib/security/cacerts -storepass changeit
For Java 11:
kind: ConfigMap
apiVersion: v1
metadata:
name: init-truststore
annotations:
controller.devfile.io/mount-as: subpath
controller.devfile.io/mount-path: /home/user/
labels:
controller.devfile.io/mount-to-devworkspace: 'true'
controller.devfile.io/watch-configmap: 'true'
data:
init-java11-truststore.sh: |
#!/usr/bin/env bash
keytool -importcert -noprompt -file /home/user/certs/tls.cer -cacerts -storepass changeit
- Apply the Secret,
settings.xml ConfigMap, and TrustStore ConfigMap to the <username>-devspaces namespace:
$ oc apply -f tls-cer.yaml -n <username>-devspaces
$ oc apply -f settings-xml.yaml -n <username>-devspaces
$ oc apply -f init-truststore.yaml -n <username>-devspaces
- Start a Maven workspace.
- Open a new terminal in the
tools container.
- Run
~/init-truststore.sh.
Results
- In the workspace terminal, verify the Maven mirror configuration:
$ mvn help:effective-settings
The output includes the mirror URLs from your settings.xml ConfigMap.
- Build a Maven project to verify artifact resolution from the mirror: