gpt4 book ai didi

maven - 将S3存储桶用作带有Gradle的Maven私有(private)存储库

转载 作者:行者123 更新时间:2023-12-01 10:26:48 28 4
gpt4 key购买 nike

我正在尝试使用AWS S3作为Maven私有(private)存储库..以下是我的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
在org.gradle.api.internal.artifacts.repositories.transport.RepositoryTransportFactory.convertPasswordCredentials(RepositoryTransportFactory.java:87)
在org.gradle.api.internal.artifacts.repositories.transport.RepositoryTransportFactory.access $ 100(RepositoryTransportFactory.java:39)
在org.gradle.api.internal.artifacts.repositories.transport.RepositoryTransportFactory $ DefaultResourceConnectorSpecification.getCredentials(RepositoryTransportFactory.java:136)
在org.gradle.internal.resource.transport.http.HttpConnectorFactory.createResourceConnector(HttpConnectorFactory.java:36)
在org.gradle.api.internal.artifacts.repositories.transport.RepositoryTransportFactory.createTransport(RepositoryTransportFactory.java:101)
在org.gradle.api.internal.artifacts.repositories.transport.RepositoryTransportFactory.createTransport(RepositoryTransportFactory.java:79)
在org.gradle.api.internal.artifacts.repositories.DefaultMavenArtifactRepository.getTransport(DefaultMavenArtifactRepository.java:122)
在org.gradle.api.internal.artifacts.repositories.DefaultMavenArtifactRepository.createResolver(DefaultMavenArtifactRepository.java:109)
在org.gradle.api.internal.artifacts.repositories.DefaultMavenArtifactRepository.createRealResolver(DefaultMavenArtifactRepository.java:100)处
在org.gradle.api.internal.artifacts.repositories.DefaultMavenArtifactRepository.createResolver(DefaultMavenArtifactRepository.java:91)处
在org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ResolveIvyFactory.create(ResolveIvyFactory.java:92)
在org.gradle.api.internal.artifacts.ivyservice.resolveengine.DefaultDependencyResolver $ 1.execute(DefaultDependencyResolver.java:92)
在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)
在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)
在org.gradle.api.internal.artifacts.ivyservice.CacheLockingArtifactDependencyResolver.resolve(CacheLockingArtifactDependencyResolver.java:40)
在org.gradle.api.internal.artifacts.ivyservice.SelfResolvingDependencyResolver.resolve(SelfResolvingDependencyResolver.java:45)
在org.gradle.api.internal.artifacts.ivyservice.ShortcircuitEmptyConfigsArtifactDependencyResolver.resolve(ShortcircuitEmptyConfigsArtifactDependencyResolver.java:58)
在org.gradle.api.internal.artifacts.ivyservice.ErrorHandlingArtifactDependencyResolver.resolve(ErrorHandlingArtifactDependencyResolver.java:47)
...另外81个

似乎由于在gradle jar-中添加的条件不正确而失败:

https://github.com/gradle/gradle/blob/master/subprojects/resources-http/src/main/java/org/gradle/internal/resource/transport/http/HttpClientConfigurer.java

有任何线索吗?

最佳答案

您面临的问题是错误的S3网址格式。

从基础Credentials接口(interface)扩展了两个接口(interface)。

  • AwsCredentials
  • 密码凭证

  • 当您使用 url 'xxxxxxxx/<Bucket-Name>/snapshots/'时,它会将Maven存储库检测为正常的URL。这就是为什么它要求 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"
    }
    }
    }

    关于maven - 将S3存储桶用作带有Gradle的Maven私有(private)存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46947716/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com