Closed kohenkatz closed 2 years ago
thank you for the questions :)
I will generate a test case for this, and will get back to you as soon as i have time.
what i will try is setting the following within the settings.gradle
applyToProject = false
like written in the documentation, but i am not sure if this will solve the issue. If not i will label this as a bug, and will start to investigate.
I revoke my last answer :)
you need to define the repositories within your settings.gradle file, like
buildscript {
gradlePluginPortal()
dependencies {
classpath 'at.schrottner.gradle.gitlab-plugin:gitlab-repositories:<version>'
}
}
apply plugin: at.schrottner.gradle.GitlabRepositoriesPlugin
gitLab {
token(PrivateToken) {
it.key = 'privateToken'
it.value = "token value, best stored in ~/.gradle/gradle.properties"
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven gitLab.project("<your project ID>")
maven gitLab.group("<your group ID>")
}
}
the rest of the configuration is pretty similar to the documentation.
It looks like this works, thank you!
Here is an example of how to use settings.gradle
with conditional token definitions based on whether the credential is set on the user's computer (since different devs on my projects want to configure it different ways).
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
buildscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath 'at.schrottner.gradle.gitlab-plugin:gitlab-repositories:0.5.0'
}
}
apply plugin: at.schrottner.gradle.GitlabRepositoriesPlugin
def gitLabPrivateToken = properties['gitLabPrivateToken']
gitLab {
applyToProject = true
baseUrl = "gitlab.example.com"
if (gitLabPrivateToken) {
token(PrivateToken) {
it.key = 'Private-Token'
it.value = gitLabPrivateToken
}
}
if (System.getenv("SM_GITLAB_TOKEN") != null) {
token(PrivateToken) {
it.key = 'Private-Token'
it.value = System.getenv("SM_GITLAB_TOKEN")
}
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
maven { url "https://jitpack.io" }
maven gitLab.project("4")
maven gitLab.group("34")
}
}
include ':app'
Just for completeness, you do not need to use the ifs to define the tokens.
If the value is empty, it will not use it. And the key
is just a identifier you can use. The header is defined by the method parameter.
Like
gitLab {
applyToProject = true
baseUrl = "dev.saferworld.live"
token(PrivateToken) {
it.key = 'privateToken'
it.value = gitLabPrivateToken
}
token(PrivateToken) {
it.key = 'smToken'
it.value = System.getenv("SM_GITLAB_TOKEN")
}
}
When creating a new project in Android Studio Bumblebee (2021.1.1 RC 1), the Gradle files have the following structure:
settings.gradle
build.gradle
app/build.gradle
The important line here is
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
insettings.gradle
. It prevents repositories from being added in thebuild.gradle
files, instead requiring them to be set here insettings.gradle
.How should this plugin be added to a project with this configuration?