I suck at gradle.. I am making a new android proje...
# community-support
a
I suck at gradle.. I am making a new android project and am starting a new. I am trying to add a gitlab repo to it, but I am not sure where I add it. I believe I know what the syntax should be, but there is confusion about the overall structure of gradle and adding repos that get added into the actual project.
t
using the blocks in the settings file is my default method for quite a while now. one for plugin repositories and one for dependencies. and I make adding in the build files an error so it stays in one place
a
this confuses me.. What I believe I should be adding is
Copy code
maven {
            url = uri("<https://gitlab>..../packages/maven")

            credentials(HttpHeaderCredentials) {
                name = "Private-Token"
                value System.getenv("PRIVATE_TOKEN")
            }
            authentication {
              header(HttpHeaderAuthentication)
            }

            content {
               includeGroupByRegex("^***.*")
            }
        }
but I'm not sure where I add it so everywhere in my project can access it, or how to stop it from being searched for in other repo's
t
in your settings.gradle file you can do it in the
dependencyResolutionManagement
block. something like this
Copy code
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        maven {
            url = uri("<https://gitlab>..../packages/maven")

            credentials(HttpHeaderCredentials) {
                name = "Private-Token"
                value System.getenv("PRIVATE_TOKEN")
            }
            authentication {
                header(HttpHeaderAuthentication)
            }

            content {
                includeGroupByRegex("^***.*")
            }
        }
    }
}
a
So that is what I did, but it is still getting a HEAD on error where it's looking for those libraries in the tak repo
e
if this is an old instance of gitlab, upgrade: https://gitlab.com/gitlab-org/gitlab/-/issues/32102
a
Its not. The issue is that it searching for the xxx library in a repo that its not in.
e
Gradle will search in all repos (that aren't rejected by content filters) until it finds the artifact. if you're not seeing the repository in the list at all, then you haven't set up the repositories correctly
a
So previously everything worked, then I add my dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { maven { url = uri("https://gitlab..../packages/maven") ... } to my settings.gradle and add
Copy code
implementation 'my.helper.libraries:xyz:3.2.0'
That should be all I'm needing to do no?
but I am getting Could not HEAD 'https://artifacts.tak.gov/artifactory/maven/my/helper/libraries/xyz/3.2.0/xyz-3.2.0.pom'. Received status code 403 from server: On a side note. The gradle version of repositoriesMode = RepositoriesMode.FAIL_ON_PROJECT_REPOS gives me A problem occurred evaluating project ':app'.
Build was configured to prefer settings repositories over project repositories but repository 'MavenRepo' was added by build file 'app\build.gradle'
That may be related...?
e
oh on a different repo?
you should fix that. Gradle will continue searching other repos if it receives a 404, but not other errors (you wouldn't want your artifact resolution to change just because of a temporary network failure)
t
Build was configured to prefer settings repositories over project repositories but repository 'MavenRepo' was added by build file 'app\build.gradle'
may need to back off that fail on project flag until you get things all sorted out
a
I mean how do I fix that? Previous builds I did something with an exclude, but I don't really have a way to do that on this.
v
If you set the mode to
FAIL_ON_PROJECT_REPOS
, that means either you set repositories in a project build script, or you apply some plugin that adds a repository, the stacktrace should tell you where it is coming from. If it is from a plugn, that plugn should have at least an opt-out switch, if not it is following really bad practice and should get a bug reported. You cannot mix repositories in settings script and build script, it is an either or. With the default, it uses settings if no project repositories are there or project repositories otherwise. If you set this to fail on project repos, you get immediately notified that someone or something is misbehaving. If you have to cope with misbehaving plugins, you can set it to prefer settings repository, then project repos will just emit a warning but otherwise be ignored.
How you fix the 403, well, make whoever maintains
<http://artifacts.tak.gov|artifacts.tak.gov>
fix their server to either deliver the content or give a 404, but not a 403, or use repository content filters to control which artifacts are taken from that repository and which are not. Or move it to the last position, so that it is only asked for artifacts not in any other repository. ...