我正在尝试使用AWS S3作为maven私人回购。我的build.gradle看起来像是:
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/"
}
}
}
}
但我收到的错误
引起:java.lang.IllegalArgumentException:凭据必须是以下实例: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) 在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) 在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) 在org.gradle.internal.Transformers $ 4.transform(Transformers.java:137) 在org.gradle.api.internal.artifacts.ivyservice.DefaultIvyContextManager.withIvy(DefaultIvyContextManager.java:61) 在org.gradle.api.internal.artifacts.ivyservice.DefaultIvyContextManager.withIvy(DefaultIvyContextManager.java:39) 在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) 在org.gradle.internal.Factories $ 1.create(Factories.java:22) 在org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:192) 在org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAccess.java:175) 在org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(DefaultPersistentDirectoryStore.java:106) 在org.gradle.cache.internal.DefaultCacheFactory $ ReferenceTrackingCache.useCache(DefaultCacheFactory.java:187) 在org.gradle.api.internal.artifacts.ivyservice.DefaultCacheLockingManager.useCache(DefaultCacheLockingManager.java:64) at org.gradle.api.internal.artifacts.ivyservice.CacheLockingArtifactDependencyResolver.resolve(CacheLockingArtifactDependencyResolver.java:40) 在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更多
由于在gradle jar中添加了错误的条件,它看起来失败了 - :
任何线索?
答案 0 :(得分:3)
您遇到的问题是错误的S3 Url模式。
有两个接口从基础Credentials
接口扩展。
当您使用url 'xxxxxxxx/<Bucket-Name>/snapshots/'
时,它会将maven repo检测为普通网址。这就是为什么要求PasswordCredentials
。
您应该使用s3://<bucket-name>.s3-eu-west-1.amazonaws.com
。在这里,它会要求AwsCredentials
。
恕我直言,你应该使用两个不同的存储桶和快照。
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"
}
}
}