Set up Gradle to use your internal registry

Set up Gradle so that Gradle workspaces can download plugins and dependencies from your internal registry. .Prerequisites

About this task

  • You are not running any Gradle workspace.

Procedure

  1. 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 Gradle artifact repository’s public TLS certificate, with line wrapping disabled.
  2. Create a ConfigMap for the TrustStore initialization script:
    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-truststore.sh: |
        #!/usr/bin/env bash
    
        keytool -importcert -noprompt -file /home/user/certs/tls.cer -cacerts -storepass changeit
  3. Create a ConfigMap for the Gradle init script:
    kind: ConfigMap
    apiVersion: v1
    metadata:
      name: init-gradle
      annotations:
        controller.devfile.io/mount-as: subpath
        controller.devfile.io/mount-path: /home/user/.gradle
      labels:
        controller.devfile.io/mount-to-devworkspace: 'true'
        controller.devfile.io/watch-configmap: 'true'
    data:
      init.gradle: |
        allprojects {
          repositories {
            mavenLocal ()
            maven {
              url "https://<gradle_artifact_repository_route>/repository/maven-public/"
              credentials {
                username "admin"
                password "passwd"
              }
            }
          }
        }

    where:

    <gradle_artifact_repository_route>
    The hostname and path of your internal Gradle artifact repository.
  4. Apply the Secret and both ConfigMaps to your project:
    $ oc apply -f tls-cer.yaml -n <your_namespace>
    $ oc apply -f init-truststore.yaml -n <your_namespace>
    $ oc apply -f init-gradle.yaml -n <your_namespace>
  5. Start a Gradle workspace.
  6. Open a new terminal in the tools container.
  7. Run ~/init-truststore.sh.

Results

  1. In the workspace terminal, build a Gradle project to verify artifact resolution from the mirror:
    $ gradle build