Skip to content

Instantly share code, notes, and snippets.

@illarionov
Created February 14, 2026 11:19
Show Gist options
  • Select an option

  • Save illarionov/11dbf2a6e7f62217071e2a75e84abfd8 to your computer and use it in GitHub Desktop.

Select an option

Save illarionov/11dbf2a6e7f62217071e2a75e84abfd8 to your computer and use it in GitHub Desktop.
Adding github credentials to all projects
// 1) Generate classic token with read:packages permission
// 2) Save this to ~/.gradle/init.d
// 3) change <token> to generated token
logger.info('Applying init.gradle to add Github credentials')
def githubCredentials = {
username = 'illarionov'
password = '<token>'
}
settingsEvaluated { settings ->
settings.dependencyResolutionManagement {
repositories.withType(org.gradle.api.artifacts.repositories.MavenArtifactRepository).matching {
it.url.host == 'maven.pkg.github.com'
}.all {
credentials(githubCredentials)
}
}
}
gradle.projectsLoaded {
rootProject.allprojects {
buildscript {
repositories.withType(org.gradle.api.artifacts.repositories.MavenArtifactRepository).matching {
it.url.host == 'maven.pkg.github.com'
}.all {
credentials(githubCredentials)
}
}
repositories.withType(org.gradle.api.artifacts.repositories.MavenArtifactRepository).matching {
it.url.host == 'maven.pkg.github.com'
}.all {
credentials(githubCredentials)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment