How can I overwrite all plugin repositories in gradle via the init script?
allprojects {
repositories {
maven { url "foo" }
}
}
only works for regular repositories - not for plugin repositories.
Plugins are registerd via the old buildscript{ repositories { }} notation
simply adding:
allprojects {
buildscript{
repositories{
maven { url "https://foo.com" }
}
}
repositories {
maven { url "https://foo.com" }
}
}
is the solution
Related
Since today, and I didn't change anything in my Gradle files, there is an error during the building:
Caused by: org.gradle.internal.resolve.ModuleVersionResolveException: Could not resolve com.squareup.okhttp3:okhttp:3.12.+.
For information in my Gradle:
allprojects {
repositories {
google()
mavenCentral()
// jcenter()
maven { url = "https://jcenter.bintray.com" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://jitpack.io" }
maven { url 'https://maven.google.com' }
maven { url "https://dl.cloudsmith.io/public/cometchat/cometchat-pro-android/maven/" }
flatDir {
dirs 'src/main/libs'
}
}
}
According to gradle status, jcenter has some issues still.
I want to connect to the Artifactory repository
https://www.artifactrepository.citigroup.net/artifactory/webapp/#/artifacts/browse/tree/General/
and download a jar using build.gradle.
I have 2 repository in my code, which I want to connect: one is local and is where I've download all Gradle related jars and the other is artifactory repository where I want to download TIBCO related jars.
but not able to connect to second repo
This is my build.gradle code
buildscript {
repositories {
maven {
url "${artifactory_contextUrl}/plugins-release"
}
maven {
url 'https://www.artifactrepository.citigroup.net/artifactory/maven-cto-dev-3rdpartymanual-local'
}
}
dependencies {
classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '2.0.9')
}
}
allprojects {
apply plugin: 'artifactory'
apply plugin: 'maven'
group = 'com.citi.recon'
task wrapper(type: Wrapper) {
distributionUrl = "${artifactory_contextUrl}/simple/ext-release-local/org/gradle/services/distributions/gradle/1.9/gradle-1.9-bin.zip"
description = 'Generates gradlew[.bat] scripts'
gradleVersion = '1.9'
}
}
artifactory {
contextUrl = "${artifactory_contextUrl}" //The base Artifactory URL if not overridden by the publisher/resolver
publish {
repository {
repoKey = 'libs-release-local'
maven = true
}
}
resolve {
repository {
repoKey = 'repo'
maven = true
}
}
}
According to Gradle documention (Example 50.27), we can use S3 backed Maven repositories with Gradle 2.4. However, the only example given in the docs passes explicit AWS credentials to the S3 repository declaration:
repositories {
maven {
url "s3://someS3Bucket/maven2"
credentials(AwsCredentials) {
accessKey "someKey"
secretKey "someSecret"
}
}
}
I need to do the same thing, but I want Gradle to use the DefaultAWSCredentialsProviderChain, from the AWS JDK, instead of explicit credentials. Something like:
repositories {
maven {
url "s3://someS3Bucket/maven2"
credentials(AwsCredentials) {
// Default AWS chain here?
}
}
}
This way, it would find the Instance Profile Credentials that I have configured for my EC2 instances where the Gradle build would be running.
Is there a way to accomplish this? Or, is Gradle only capable of authenticating against S3 with explicit credentials given in the build file?
More recent versions of Gradle provide a built-in way to use credentials from the default provider chain, eg:
maven {
url "s3://myCompanyBucket/maven2"
authentication {
awsIm(AwsImAuthentication) // load from EC2 role or env var
}
}
This avoids the need to manually create an instance of the provider chain and pass in the credential values.
I managed to accomplish the pom.xml generation, as well as the upload to S3, with the following build.gradle:
apply plugin: 'java'
apply plugin: 'maven-publish'
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.amazonaws:aws-java-sdk:1.10.58'
}
}
publishing {
publications {
mavenJava(MavenPublication) {
groupId 'com.acme'
artifactId 'sample-gradle-dependency'
version '1.0'
from components.java
}
}
repositories {
maven {
url "s3://my-bucket/releases"
credentials(AwsCredentials) {
def defaultCredentials = new com.amazonaws.auth.DefaultAWSCredentialsProviderChain().getCredentials()
accessKey defaultCredentials.getAWSAccessKeyId()
secretKey defaultCredentials.getAWSSecretKey()
}
}
}
}
This one requires apply plugin: maven-publish, which apparently is the new version of apply plugin: maven.
This one runs with:
$ gradle publish
Untested, but I would try:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.amazonaws:aws-java-sdk:1.10.58'
}
}
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain
repositories {
maven {
url "s3://someS3Bucket/maven2"
credentials(AwsCredentials) {
def defaultCredentials = new DefaultAWSCredentialsProviderChain().getCredentials()
accessKey defaultCredentials.getAWSAccessKeyId()
secretKey defaultCredentials.getAWSSecretKey()
}
}
}
So my problem is how to add multiple maven repositories to one gradle file.
This DOESN’T work:
repositories {
mavenCentral()
maven {
url "http://maven.springframework.org/release"
url "http://maven.restlet.org"
}
}
you have to do like this in your project level gradle file
allprojects {
repositories {
jcenter()
maven { url "http://dl.appnext.com/" }
maven { url "https://maven.google.com" }
}
}
I have a gradle project that acts like a common library for two other projects.
The other two projects each hosts an embedded maven repository that I want the common project to deploy to.
I've tried this:
uploadArchives {
repositories {
mavenDeployer {
repositories {
repository(url: '../../../project-web-service/repo')
repository(url: '../../../project-app/repo')
}
}
}
}
But this only deploys to the second repo.
I have read Configuring multiple upload repositories in Gradle build, but it doesn't cover the mavenDeployer, so I'm kind of stuck right now.
You can create two your own tasks (extends from Upload), just like this:
task uploadFirst(type: Upload) {
uploadDescriptor = true
repositories {
mavenDeployer {
repositories {
repository(url: '../../../project-web-service/repo')
}
}
}
}
task uploadSecond(type: Upload) {
uploadDescriptor = true
repositories {
mavenDeployer {
repositories {
repository(url: '../../../project-app/repo')
}
}
}
}
I had the same issue and was just able to solve it by giving the additional repositories names, but still leaving their own mavenDeployer closure.
For your example:
uploadArchives {
repositories {
mavenDeployer {
name = 'WebService'
repository(url: '../../../project-web-service/repo')
}
mavenDeployer {
name = 'App'
repository(url: '../../../project-app/repo')
}
}
}