docker gradle : how to use host .gradle/gradle.properties file?

Viewed 131

I'm using docker gradle to build my project in a docker container like :

#stage 1
FROM gradle:7.3-jdk11-alpine as build
USER gradle
WORKDIR /app
COPY --chown=gradle:gradle . ./
RUN gradle build

#stage 2
from openjdk:11-slim
...

The problem is I'm using urls in my build.gradle that are defined in the host /home/me/.gradle/gradle.properties file:

build.gradle

buildscript {
    
    repositories {
        mavenLocal()
        maven {
            url = "${artifactoryUrl}"
            credentials {
                username = "${artifactoryUsername}"
                password = "${artifactoryPassword}"
            }
        }
    }
    //...
}

and gradle.properties

artifactoryUrl=https://xxxx/artifactory/xxxx/
artifactoryReleaseRepository=https://xxxx/artifactory/xxxx
artifactorySnapshotRepository=https://xxxx/artifactory/xxxx

artifactoryUsername=xxxx
artifactoryPassword=xxxx

org.gradle.java.home=xxxx

systemProp.javax.net.ssl.keyStore=xxxx/xxxx.p12
systemProp.javax.net.ssl.keyStoreType=xxxx
systemProp.javax.net.ssl.keyStorePassword=xxxx

when running this docker command to build my image :

$: docker build --progress=plain -t my-deploy .

I get this error (gradle cannot resolve artifactoryUrl) :

#25 11.89 FAILURE: Build failed with an exception.
#25 11.89 
#25 11.89 * Where:
#25 11.89 Build file '/app/build.gradle' line: 24
#25 11.89 
#25 11.89 * What went wrong:
#25 11.89 A problem occurred evaluating root project 'my-project-boot'.
#25 11.89 > Could not get unknown property 'artifactoryUrl' for object of type org.gradle.api.internal.artifacts.repositories.DefaultMavenArtifactRepository.
#25 11.89 
#25 11.89 * Try:
#25 11.89 > Run with --stacktrace option to get the stack trace.
#25 11.89 > Run with --info or --debug option to get more log output.
#25 11.89 > Run with --scan to get full insights.

Is there any way to tell docker to use the host /home/me/.gradle/gradle.properties when building the image ?

0 Answers
Related