question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple repository set, repository with credentials in Gradle

See original GitHub issue

I really like the idea behind this gradle plugin, however I found the settings thin too.

Actually there is a gradle repo for the co-workers in our company, but this repo is only reachable with credential data. There are stored the common libs. So my gradle file looks like this:

repositories {
    mavenCentral()
    maven { url "https://repo.spring.io/snapshot" }
    maven { url "https://repo.spring.io/milestone" }
    maven {
        url "https://...."
        credentials {
            username = "${readerJfrogUser}"
            password = "${readerJfrogUserPw}"
        }
    }
}

Its working fine If I build my stuff the original way, however, I can not set multiple repo url, and credentials (for them) in the settings section.

Can it be a future feature? Or has somebody any workaround ?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
dsyercommented, Nov 19, 2019

We seem to have veered off topic from the original issue though, or am I missing something? The original topic was about custom repositories with credentials. It wasn’t anything to do with multistage docker builds and optimization of docker caches.

All you need to make it work is a Maven settings.xml with the repository credentials. You have to figure out a way to inject the secrets from environment variables, but I know it’s possible (plenty of docs if you google), and you already have that problem with the build.gradle, so you must have solved it somehow.

0reactions
GergelyLakatoscommented, Nov 19, 2019

Okey, let me explain. We dont have this cache option, because our build system is not an usual one.

Dockerfile looks like this:

FROM openjdk:11-jre-slim AS base
WORKDIR /app


FROM gradle:5.5.1-jdk11 AS build
COPY . /src
WORKDIR /src
RUN ["gradle", "clean", "build", "-PexcludeRepoTests"]


FROM base AS final
COPY --from=build /src/build/libs/myapp* /app/myapp.jar
ENTRYPOINT ["java", "-jar", "/app/myapp.jar"]

So we have no gradle cache in the jenkins (build) server, because we use a docker image for build (gradle:5.5.1-jdk11), and an another one for run it (openjdk:11-jre-slim). Our jenkins is abstract, and it handles nothing but docker build, and deploy.

So (with your solution), I have to make an automation, for making a builder docker image what would contain all the dependencies what it need for the build, and it should be changed as the deps changes… Its complicated.

My goal was a Dockerfile like this:

FROM openjdk:11-jre-slim AS base
WORKDIR /app


FROM gradle:5.5.1-jdk11 AS build
COPY . /src
WORKDIR /src
RUN ["gradle", "clean", "buildonlydependencies"] # it makes the jar of dependencies
RUN ["gradle", "clean", "buildcore", "-PexcludeRepoTests"] # it makes the core jar and runs the tests


FROM base AS final
COPY --from=build /src/build/libs/myapp* /app/myapp.jar
ENTRYPOINT ["java", "-jar", "/app/myapp.jar"]

And why is it good for me? Because if a gradle command like buildonlydependencies would exist, the docker would handle it so well, because it can make a cache layer from it, so that step would come from the docker cache (if the deps does not change), and most of the time the build process should focus only the core.jar.

I hope you can understand now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Declaring repositories - Gradle User Manual
Accessing authenticated Maven repositories. You can specify credentials for Maven repositories secured by different type of authentication. See Supported ...
Read more >
Same credentials for all repositories in Gradle - Stack Overflow
Maybe you know - how in one place set same credentials for all maven repositories? I don't want to copy the same code...
Read more >
Gradle Repositories - NovaOrdis Knowledge Base
Use properties instead of credentials in clear in build.gradle, and then initialize those properties into a local file, such as ~/.gradle/gradle ...
Read more >
Maven artifacts | Bytesafe Documentation
Alternative mirror setup · Add multiple upstream sources for a registry · Provide project level configuration for package repository · Using Bytesafe together...
Read more >
Adding Password Protected Maven Repository URL in Gradle
In my current project at work, I had to setup a private maven repository hosted at Artifactory. I was assigned login credentials to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found