我尝试将库发布到私有 S3 Maven 存储库。上传受密码保护,但下载库对公众开放。aar 文件上传没有问题(连同 pom/md5/sha1),我可以在我的 S3 存储桶中看到它,下载它,甚至手动将此 aar 作为依赖项添加到我的项目中。但是,当我像这样加载此依赖项时:
allprojects {
repositories {
google()
jcenter()
maven { url "http://myrepo.com" }
}
//in the project's build.gradle
implementation 'com.mylib:mylib:0.1.1'
……有问题。Gradle 同步完成没有问题,看起来 aar 已经下载,但它从未出现在 Android Studio 的“外部库”部分中,并且代码不可用(Unresolved reference: MyLib
)。
当然,我尝试重建、使缓存无效并将其应用于不同的项目。
任何想法如何使它工作?
这就是 maven-publish 代码的样子。
android.libraryVariants.all { variant ->
if (variant.buildType.name == "release" && variant.flavorName == "prod") {
variant.outputs.all { output ->
publishing.publications.create(variant.name, MavenPublication) {
artifact source: output.outputFile, classifier: output.name
pom.withXml {
def dependencies = asNode().appendNode('dependencies')
configurations.getByName(variant.name + "CompileClasspath").allDependencies
.findAll { it instanceof ExternalDependency }
.each {
def dependency = dependencies.appendNode('dependency')
dependency.appendNode('groupId', it.group)
dependency.appendNode('artifactId', it.name)
dependency.appendNode('version', it.version)
}
}
}
}
}
}
tasks.all { task ->
if (task instanceof AbstractPublishToMaven) {
task.dependsOn assemble
}
}
publishing {
Properties properties = new Properties()
properties.load(file('maven.properties').newDataInputStream())
def user = properties.getProperty("maven.user")
def password = properties.getProperty("maven.password")
repositories {
maven {
url "s3://myrepo.com/"
credentials(AwsCredentials) {
accessKey user
secretKey password
}
}
}
}