Last active
December 12, 2015 08:18
-
-
Save jdigger/4742917 to your computer and use it in GitHub Desktop.
Initialization script (in ~/.gradle) to add my credentials for repos.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.gradle.api.artifacts.repositories.AuthenticationSupported | |
import org.gradle.api.tasks.Upload | |
import org.gradle.api.publication.maven.internal.ant.RepositoryBuilder | |
apply from: 'config.gradle' | |
logger.info "Applying init.gradle to add Artifactory credentials for ${security.host}" | |
gradle.projectsEvaluated { | |
security.each {secRepoConfig -> | |
rootProject.allprojects { | |
buildscript { | |
repositories.withType(AuthenticationSupported).matching { it.url.host == secRepoConfig.host }.all { | |
credentials { | |
username = secRepoConfig.username | |
password = secRepoConfig.password | |
} | |
} | |
} | |
tasks.withType(Upload).all {uTask -> | |
uTask.repositories.matching { it.hasProperty('repository') && URI.create(it.repository.url).host == secRepoConfig.host }.all {rep -> | |
def rb = new RepositoryBuilder() | |
def auth = rb.factories.authentication.newInstance(rb, "authentication", null, null) | |
auth.userName = secRepoConfig.username | |
auth.password = secRepoConfig.password | |
rep.repository.authentication = auth | |
} | |
} | |
repositories.withType(AuthenticationSupported).matching { it.url.host == secRepoConfig.host }.all { | |
credentials { | |
username = secRepoConfig.username | |
password = secRepoConfig.password | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment