aepfli / gradle-gitlab-repositories

Handling Maven GitLab dependencies made easy. Define multiple tokens and selectively apply them to repositories, remove the need for repeating Credential handling blocks for different environments.
Eclipse Public License 2.0
13 stars 1 forks source link

Option to not automatically add repository to all projects at 'apply' #59

Closed t-kulmburg closed 1 year ago

t-kulmburg commented 1 year ago

hi,

when applying the plugin in settings.gradle, the applyProjects method automatically adds the GitLab repo to all projects via gradle.beforeProject and further project.repositories.maven.

This can be convenient, but also means that when entering the repositories block in build.gradle and adding more repos like mavenCentral, they are behind the GitLab repo in the repositories list. As Gradle checks repositories for dependencies in the order the repos are added, it will search for all dependencies in the added GitLab repo before looking them up in the central maven repo.

Since only a small part of our dependencies are actually in the private repo, it would be better to check mavenCentral beforehand.

An idea would be adding the possibillity to choose if the GitLab repo should be added to all projecs by only applying the plugin, as it happens now. If preferred not to, the repo can still be added to a project via maven gitLab.group('123456') { name = "gitlabgroup" } in the repositories block in the build.gradle. This would allow us to sort the repositories in the way we would like them to be checked.

My current workaround for this is adding the following code block to the settings.gradle file, to add one or more repos before the plugin is applied.

gradle.beforeProject { project ->
  project.repositories {
    mavenCentral()
  }
}

apply plugin: 'at.schrottner.gitlab-repositories'
aepfli commented 1 year ago

there are multiple take on this:

  1. you can only apply as you like eg. by setting applyToProject to false and manually add the projects on each project
  2. what you actually want is a better way of filtering for repositories and a better integration with default features of gradle and content filtering like https://docs.gradle.org/current/userguide/declaring_repositories.html#sec:repository-content-filtering

so far I did not have the time and/or need to implement this see https://github.com/aepfli/gradle-gitlab-repositories/issues/3

content filtering would be anyway the approach, because people could upload packages with the same group to anykind of other repository executed first. so ideally you want to first check for internal ones, and then check on the public ones. Yes mavencentral is quiet good and secure, but specially for company internal things, you want to first check on your repos.

if you want to take a shot at this let me know, I can support you and will be happy to guide you.

tobijdc commented 1 year ago

applyToProject=false looks like the way for us Me and @t-kulmburg somehow both overlooked this when looking at the code. Filtering would be a cool feature, but at the moment we simply exclude known internal dependencies from the public repositories, so no need for that for us at the moment.

Thx for your quick reply

aepfli commented 1 year ago

Take a look at the comment in #3 that allows even easy and fast filtering ;)