uploadArchives with mavenDeployer to multiple repos - gradle

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')
}
}
}

Related

Gradle: Could not resolve com.squareup.okhttp3:okhttp:3.12.+

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.

gradle overwrite plugin repository from init script

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

Using S3 Bucket as Maven private repository with gradle

I am trying to use AWS S3 as a maven private repo..below is my build.gradle looks like-:
import java.util.regex.Matcher
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.amazonaws:aws-java-sdk-core:1.11.5'
}
}
plugins {
id "java"
id "idea"
id "eclipse" //run "./gradlew cleanEclipse eclipse" after importing to eclipse
id "maven-publish"
id "maven"
id 'base'
id 'signing'
id 'jacoco'
id "net.researchgate.release" version "2.4.1"
id "org.springframework.boot" version "1.5.2.RELEASE"
}
def fetchAwsCredentials = {
try {
return new ProfileCredentialsProvider().getCredentials()
} catch (Exception e) {
logger.debug('Unable to retrieve AWS credentials from profile, publishing to S3 will not be available.', e)
return null
}
}
AWSCredentials awsCredentials = fetchAwsCredentials()
repositories {
mavenCentral()
maven {
url 'xxxxxxxx/<Bucket-Name>/snapshots/'
credentials(AwsCredentials) {
accessKey awsCredentials.AWSAccessKeyId
secretKey awsCredentials.AWSSecretKey
}
}
}
publish {
dependsOn assemble
}
publishing {
publications {
maven(MavenPublication) {
groupId this.properties['group']
artifactId this.properties['mavenArtifactId']
from components.java
}
}
repositories {
maven {
name 'repo'
credentials(AwsCredentials) {
accessKey awsCredentials.AWSAccessKeyId
secretKey awsCredentials.AWSSecretKey
}
if (project.version.endsWith('-SNAPSHOT')) {
url "xxxxxxxx/<Bucket-Name>/snapshots/"
} else {
url "xxxxxxxx/<Bucket-Name>/releases/"
}
}
}
}
But I am getting below error
Caused by: java.lang.IllegalArgumentException: Credentials must be an instance of: org.gradle.api.artifacts.repositories.PasswordCredentials
at org.gradle.api.internal.artifacts.repositories.transport.RepositoryTransportFactory.convertPasswordCredentials(RepositoryTransportFactory.java:87)
at org.gradle.api.internal.artifacts.repositories.transport.RepositoryTransportFactory.access$100(RepositoryTransportFactory.java:39)
at org.gradle.api.internal.artifacts.repositories.transport.RepositoryTransportFactory$DefaultResourceConnectorSpecification.getCredentials(RepositoryTransportFactory.java:136)
at org.gradle.internal.resource.transport.http.HttpConnectorFactory.createResourceConnector(HttpConnectorFactory.java:36)
at org.gradle.api.internal.artifacts.repositories.transport.RepositoryTransportFactory.createTransport(RepositoryTransportFactory.java:101)
at org.gradle.api.internal.artifacts.repositories.transport.RepositoryTransportFactory.createTransport(RepositoryTransportFactory.java:79)
at org.gradle.api.internal.artifacts.repositories.DefaultMavenArtifactRepository.getTransport(DefaultMavenArtifactRepository.java:122)
at org.gradle.api.internal.artifacts.repositories.DefaultMavenArtifactRepository.createResolver(DefaultMavenArtifactRepository.java:109)
at org.gradle.api.internal.artifacts.repositories.DefaultMavenArtifactRepository.createRealResolver(DefaultMavenArtifactRepository.java:100)
at org.gradle.api.internal.artifacts.repositories.DefaultMavenArtifactRepository.createResolver(DefaultMavenArtifactRepository.java:91)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ResolveIvyFactory.create(ResolveIvyFactory.java:92)
at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DefaultDependencyResolver$1.execute(DefaultDependencyResolver.java:92)
at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DefaultDependencyResolver$1.execute(DefaultDependencyResolver.java:90)
at org.gradle.internal.Transformers$4.transform(Transformers.java:137)
at org.gradle.api.internal.artifacts.ivyservice.DefaultIvyContextManager.withIvy(DefaultIvyContextManager.java:61)
at org.gradle.api.internal.artifacts.ivyservice.DefaultIvyContextManager.withIvy(DefaultIvyContextManager.java:39)
at org.gradle.api.internal.artifacts.ivyservice.resolveengine.DefaultDependencyResolver.resolve(DefaultDependencyResolver.java:90)
at org.gradle.api.internal.artifacts.ivyservice.CacheLockingArtifactDependencyResolver$1.run(CacheLockingArtifactDependencyResolver.java:42)
at org.gradle.internal.Factories$1.create(Factories.java:22)
at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:192)
at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:175)
at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:106)
at org.gradle.cache.internal.DefaultCacheFactory$ReferenceTrackingCache.useCache(DefaultCacheFactory.java:187)
at org.gradle.api.internal.artifacts.ivyservice.DefaultCacheLockingManager.useCache(DefaultCacheLockingManager.java:64)
at org.gradle.api.internal.artifacts.ivyservice.CacheLockingArtifactDependencyResolver.resolve(CacheLockingArtifactDependencyResolver.java:40)
at org.gradle.api.internal.artifacts.ivyservice.SelfResolvingDependencyResolver.resolve(SelfResolvingDependencyResolver.java:45)
at org.gradle.api.internal.artifacts.ivyservice.ShortcircuitEmptyConfigsArtifactDependencyResolver.resolve(ShortcircuitEmptyConfigsArtifactDependencyResolver.java:58)
at org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingArtifactDependencyResolver.resolve(ErrorHandlingArtifactDependencyResolver.java:47)
... 81 more
Looks like it failing because of incorrect condition added in gradle jar-:
https://github.com/gradle/gradle/blob/master/subprojects/resources-http/src/main/java/org/gradle/internal/resource/transport/http/HttpClientConfigurer.java
Any Clue ?
The problem you are facing is for wrong S3 Url pattern.
There are two interfaces extends from base Credentials interface.
AwsCredentials
PasswordCredentials
When you used url 'xxxxxxxx/<Bucket-Name>/snapshots/', it detects the maven repo as just normal url. That is why it was asking for PasswordCredentials.
You should use s3://<bucket-name>.s3-eu-west-1.amazonaws.com. Here it will ask for AwsCredentials.
IMHO you should use two different buckets for releases and snapshots.
repositories {
maven {
name 'repo'
credentials(AwsCredentials) {
accessKey awsCredentials.AWSAccessKeyId
secretKey awsCredentials.AWSSecretKey
}
if (project.version.endsWith('-SNAPSHOT')) {
url "s3://<bucket-name>-snapshots.s3-eu-west-1.amazonaws.com"
} else {
url "s3://<bucket-name>-releases.s3-eu-west-1.amazonaws.com"
}
}
}

Gradle is not able to use dependencies from artifactory

This is the code I have written: Please be notified that the code is working when I enable the flatDir section (commented one in the code), but not working when I want to use Remote Artifactory repository (Means comment the flatDir part):
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4+"
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'distribution'
buildDir = new File("$buildPath", project.name)
ext.distributionDir = new File(project.buildDir, 'distribution')
sourceSets {
//SourceSets
}
ext.sharedManifest = manifest {
//Manifests
}
tasks.withType(Jar) {
//Code to generate Jar Artifacts
}
// repositories {
// flatDir {
// dirs file("$dependencyPath"),
// }
// }
allprojects {
artifactory {
contextUrl = "${artifactory_contextUrl}"
publish {
repository {
repoKey = 'gradle-dev-local'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
resolve {
repository {
repoKey = 'gradle-dev'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
}
}
}
project(':projectName:ProjectComponent') {
sourceSets {
main {
java { include '/pathToCode/*' }
}
}
dependencies { compile (group: 'jcifs', name: 'jcifs', version: '1.1.11')}
//******* Publishing Component Jar (Build artifacts on Remote Repository) ********//
publishing.publications {
mavenJava(MavenPublication) {
groupId 'GroupID'
artifactId project.name
version = projVersion
from components.java
}
}
artifactoryPublish {
publications(publishing.publications.mavenJava)
}
}
Please suggest the solution.
Thanks! :-)

Multiple maven repositories in one gradle file

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" }
}
}

Resources