{"id":20612122,"url":"https://github.com/aepfli/gradle-gitlab-repositories","last_synced_at":"2025-10-19T00:45:19.288Z","repository":{"id":39614442,"uuid":"336872627","full_name":"aepfli/gradle-gitlab-repositories","owner":"aepfli","description":"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.","archived":false,"fork":false,"pushed_at":"2025-04-11T23:39:59.000Z","size":229,"stargazers_count":13,"open_issues_count":19,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-15T05:43:15.931Z","etag":null,"topics":["gitlab","gradle-plugins","hacktoberfest"],"latest_commit_sha":null,"homepage":"","language":"Groovy","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"epl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aepfli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-02-07T19:35:28.000Z","updated_at":"2024-08-04T19:19:48.000Z","dependencies_parsed_at":"2023-09-29T03:38:55.838Z","dependency_job_id":"fdcd9dea-f608-402e-8773-fcef6b6d6ec4","html_url":"https://github.com/aepfli/gradle-gitlab-repositories","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aepfli%2Fgradle-gitlab-repositories","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aepfli%2Fgradle-gitlab-repositories/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aepfli%2Fgradle-gitlab-repositories/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aepfli%2Fgradle-gitlab-repositories/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aepfli","download_url":"https://codeload.github.com/aepfli/gradle-gitlab-repositories/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249016308,"owners_count":21198829,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gitlab","gradle-plugins","hacktoberfest"],"created_at":"2024-11-16T10:23:20.480Z","updated_at":"2025-10-19T00:45:14.249Z","avatar_url":"https://github.com/aepfli.png","language":"Groovy","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Gradle GitLab Repositories Plugin\n\nHandling Maven GitLab dependencies easy. Define multiple tokens and selectively apply them to repositories.\n\nAdding a GitLab repository to your project is tiresome, based on the documentation you need to have different Tokens in\nplace for different systems.\nThe [GitLab Documentation](https://docs.gitlab.com/ee/user/packages/maven_repository/#authenticate-to-the-package-registry-with-gradle)\nshows the different types of Tokens, which can be used.\n\nThere are:\n\n- Job-Tokens for CI\n- Private-Tokens for Users\n- Deploy-Tokens for external systems\n\nAdditionally, all tokens use a different name for the HttpHeaderCredentials.\n\nSometimes, there is even the need for gradle-plugin specific repositories and for project specific ones, which can also\noverlap.\n\nThis plugin tries to cover this by allowing to reapply the same plugins, even to each project.\n\n## Background\n\nWe were in the migration phase from self-hosted development infrastructure (SCM, Nexus, Jenkins, SonarQube) to GitLab\nand Sonarcloud.io. During the migration phase we needed to support all 3 types of Tokens:\n\n- Job Token for GitLab CI\n- Deploy Token for 3rd Party systems like Jenkins\n- Private Token for local development\n\nConfiguring multiple repositories with repeated configuration was bloating our gradle files. Additionally, minor\nmistakes like forgetting some parts in the configuration, made it really hard to migrate and follow up.\n\nIn the end we investigated and come up with this solution. It will for sure fit not all needs, but it is a starting\npoint. It might help others to easily setup this configuration and if there is demand, there is also room for\nimprovements.\n\n# Usage\n\n## Configuration\n\n### Groovy DSL\n```groovy\ngitLab {\n\t/**\n\t * Token configuration also the order in which we try to apply them. \n\t * The key is the name of the token, and the value will be used for application. \n\t * Currently we do have 3 different token classes: \n\t * - PrivateToken \n\t * - DeployToken \n\t * - JobToken (will be always added by default, based on CI_JOB_TOKEN)\n\t * */\n\ttoken(PrivateToken) {\n\t\tit.key = 'private'\n\t\tit.value = gitLabPrivateToken // assumed variable in gradle.properties\n\t}\n\ttoken(DeployToken) {\n\t\tit.key = 'deploy'\n\t\tit.value = System.getenv(\"GITLAB_DEPLOY_TOKEN\")\n\t}\n}\n```\n\n### Kotlin DSL\n\n```kotlin\nconfigure\u003cGitlabRepositoriesExtension\u003e {\n    /**\n     * Token configuration also the order in which we try to apply them.\n     * The key is the name of the token, and the value will be used for application.\n     * Currently we do have 3 different token classes:\n     * - PrivateToken \"private\"\n     * - DeployToken \"deploy\"\n     * - JobToken (will be always added by default, based on CI_JOB_TOKEN)\n     * */\n    token(\"private\", {\n        key = \"private\"\n        value = \"\"\n    })\n    token(\"deploy\", {\n        key = \"tokenAdded\"\n        value = System.getenv(\"GITLAB_DEPLOY_TOKEN\")\n    })\n}\n\n```\n\n## Applying the plugin\n\nThe plugin can be used within `build.gradle` and within `settings.gradle`.\n\nIf there is no need to apply special repositories to the `build.gradle` it might be enough, to just apply it to the\nsettings.\n\n### Groovy DSL\n\n#### build.gradle\n\n```groovy\nplugins {\n\tid 'at.schrottner.gitlab-repositories' version '\u003cversion\u003e'\n}\n```\n\n#### settings.gradle\n\n```groovy\nbuildscript {\n\t// ...\n\tdependencies {\n\t\tclasspath 'at.schrottner.gradle.gitlab-plugin:gitlab-repositories:\u003cversion\u003e'\n\t}\n}\n\napply plugin: 'at.schrottner.gitlab-repositories'\n```\n\n### Kotlin DSL\n\n#### build.gradle.kts\n\n```kotlin\nplugins {\n    id(\"at.schrottner.gitlab-repositories\") version \"\u003cversion\u003e\"\n}\n```\n\n#### settings.gradle.kts\n\n```kotlin\nbuildscript {\n    // ..\n    dependencies {\n        classpath(\"at.schrottner.gradle.gitlab-plugin:gitlab-repositories:\u003cversion\u003e\")\n    }\n}\n\napply(plugin = \"at.schrottner.gitlab-repositories\")\n```\n\n## Repository handling\n\n### Adding repositories for dependencies\n\nThe plugin offers you a nice helper method inspired by `gradle-jruby-plugin` to easily add repositories.\n\n#### Groovy DSL\n\n```groovy\nrepositories {\n\tmaven gitLab.project(projectId)\n\tmaven gitLab.project(projectId) {\n\t\tname = \"custom name\"\n\t\ttokenSelektor = \"\" // a name of a configured token\n\t\ttokenSelectors = [] // a list of configured tokens, which will be checked based on their order in this set\n\t}\n\tmaven gitLab.group(groupId)\n\tmaven gitLab.group(groupId) {\n\t\tname = \"custom name\"\n\t\ttokenSelektor = \"\" // a name of a configured token\n\t\ttokenSelectors = [] // a list of configured tokens, which will be checked based on their order in this set\n\t}\n}\n```\n\n#### Kotlin DSL\n\n```kotlin\nrepositories {\n    val gitLab = the\u003cGitlabRepositoriesExtension\u003e()\n    maven(gitLab.project(projectId))\n    maven(gitLab.project(projectId) {\n        name.set(\"custom name\")\n        tokenSelektor.set(\"\") // a name of a configured token\n        tokenSelectors.addAll(/*...*/) // a list of configured tokens, which will be checked based on their order in this set\n    })\n    maven(gitLab.group(groupId))\n    maven(gitLab.group(groupId) {\n        name.set(\"custom name\")\n        tokenSelektor.set(\"\") // a name of a configured token\n        tokenSelectors.addAll(/*...*/) // a list of configured tokens, which will be checked based on their order in this set\n    })\n}\n```\n\n### Adding repositories for publishing\n\nBe aware that this has to be a projectId - you are not able to upload to groups!\n\n#### Groovy DSL\n\nFor adding a repository to the maven-publish repositories please use following method.\n\n```groovy\npublishing {\n    repositories {\n        maven gitLab.upload(projectId)\n        maven gitLab.upload(projectId) {\n            name = \"custom name\"\n            tokenSelektor = \"\" // a name of a configured token\n            tokenSelectors = [] // a list of configured tokens, which will be checked based on their order in this set\n        }\n    }\n}\n```\n\n#### Kotlin DSL\n\n```kotlin\npublishing {\n    repositories {\n        val gitLab = the\u003cGitlabRepositoriesExtension\u003e()\n        maven(gitLab.upload(projectId) {\n            name.set(\"GitLab\")\n            tokenSelector.set(\"testToken\")\n        })\n    }\n}\n```\n\n### Adding a repository with defaults\n\nThis will add a repository and will apply conditions for the first token matching, and not being empty.\n\n```groovy\n// pluginManagment.repositories { // when in settings.gradle\nrepositories {\n\tmaven gitLab.project(1)\n\tmaven gitLab.group(1)\n}\n\n```\n\n### Adding a repository with specific tokens\n\nWe can define which tokens should be taken into account (currently order of parameter is ignored)\n\n```groovy\ngitLab.project(1) {\n\ttokenSelectors = ['private', 'deploy']\n}\ngitLab.group(1) {\n\ttokenSelectors = ['private', 'deploy']\n}\n```\n\nAdditionally, we can provide one specific token to be used, if the token is not set, or empty, nothing will be done.\n\n```groovy\ngitLab.project(1) { tokenSelector = 'deploy' }\ngitLab.group(1) { tokenSelector = 'deploy' }\n```\n\n## Comparison\n\nwith the plugin\n\n```groovy\nplugins {\n\tid 'maven'\n\tid 'maven-publish'\n\tid 'at.schrotter.gitlab-repositories' version '\u003cversion\u003e'\n}\n\ngitLab {\n\t// jobToken will be applied automatically\n\ttoken(DeployToken) {\n\t\tname = \"deployToken\"\n\t\tvalue = System.getenv(\"GITLAB_DEPLOY_TOKEN\")\n\t}\n\ttoken(PrivateToken) {\n\t\tname = \"privateToken\"\n\t\tvalue = gitLabPrivateToken\n\t}\n}\n\nrepositories {\n\tmaven gitLab.group(\"ID\")\n}\n\npublishing {\n\trepositories {\n\t\tmaven gitLab.upload(\"ID\")\n\t}\n}\n```\n\nwithout this plugin\n\n```groovy\nplugins {\n\tid 'maven'\n\tid 'maven-publish'\n}\n\nrepositories {\n\tmaven {\n\t\turl 'GitLab Url with ID'\n\t\tname \"GitLab\"\n\t\tif (System.getenv(\"CI_JOB_TOKEN\")) {\n\t\t\tcredentials(HttpHeaderCredentials) {\n\t\t\t\tname = 'Job-Token'\n\t\t\t\tvalue = System.getenv(\"CI_JOB_TOKEN\")\n\t\t\t}\n\t\t} else if (System.getenv(\"GITLAB_DEPLOY_TOKEN\")) {\n\t\t\tcredentials(HttpHeaderCredentials) {\n\t\t\t\tname = 'Deploy-Token'\n\t\t\t\tvalue = System.getenv(\"GITLAB_DEPLOY_TOKEN\")\n\t\t\t}\n\t\t} else {\n\t\t\tcredentials(HttpHeaderCredentials) {\n\t\t\t\tname = 'Private-Token'\n\t\t\t\tvalue = gitLabPrivateToken\n\t\t\t}\n\t\t}\n\t\tauthentication {\n\t\t\theader(HttpHeaderAuthentication)\n\t\t}\n\t}\n}\n\npublishing {\n\trepositories {\n\t\tmaven {\n\t\t\turl 'GitLab Url with ID'\n\t\t\tname \"GitLab\"\n\t\t\tif (System.getenv(\"CI_JOB_TOKEN\")) {\n\t\t\t\tcredentials(HttpHeaderCredentials) {\n\t\t\t\t\tname = 'Job-Token'\n\t\t\t\t\tvalue = System.getenv(\"CI_JOB_TOKEN\")\n\t\t\t\t}\n\t\t\t} else if (System.getenv(\"GITLAB_DEPLOY_TOKEN\")) {\n\t\t\t\tcredentials(HttpHeaderCredentials) {\n\t\t\t\t\tname = 'Deploy-Token'\n\t\t\t\t\tvalue = System.getenv(\"GITLAB_DEPLOY_TOKEN\")\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tcredentials(HttpHeaderCredentials) {\n\t\t\t\t\tname = 'Private-Token'\n\t\t\t\t\tvalue = gitLabPrivateToken\n\t\t\t\t}\n\t\t\t}\n\t\t\tauthentication {\n\t\t\t\theader(HttpHeaderAuthentication)\n\t\t\t}\n\t\t}\n\t}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faepfli%2Fgradle-gitlab-repositories","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faepfli%2Fgradle-gitlab-repositories","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faepfli%2Fgradle-gitlab-repositories/lists"}