Mic*_*ł K 9 android gradle maven maven-publish gradle-plugin
我尝试将库发布到私有S3 maven存储库.上传由密码保护,但是为了下载,该库是公开的.aar文件上传没有问题(以及pom/md5/sha1),我可以在我的S3存储桶中看到它,下载它甚至手动添加这个作为依赖项到我的项目.但是当我像这样加载这个依赖:
allprojects {
repositories {
google()
jcenter()
maven { url "http://myrepo.com" }
}
//in the project's build.gradle
implementation 'com.mylib:mylib:0.1.1'
Run Code Online (Sandbox Code Playgroud)
......有一个问题.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
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
显然那些部署插件(这个和bintray也是如此)在涉及风味时会有一些主要的困难.我不知道具体细节,但它与他们试图根据文件名解析工件名称有关.这一行:
artifact source: output.outputFile, classifier: output.name
Run Code Online (Sandbox Code Playgroud)
是我的文物被命名的原因,例如com/mylib/mylib/0.1.1/mylib-0.1.1-prod-release.aar.以某种方式从maven加载依赖项时无法识别.将此行更改为:
artifact source: output.outputFile, classifier: null
Run Code Online (Sandbox Code Playgroud)
使文件看起来像这样com/mylib/mylib/0.1.1/mylib-0.1.1.aar显然很好.
我不知道为什么第一种命名方式不起作用,我假设有一个设置可以将它传播到元数据.在这个问题上仍然有赏金,所以也许有人可以解决这个谜团吗?
| 归档时间: |
|
| 查看次数: |
314 次 |
| 最近记录: |