我有一个Android库项目,我正在尝试使用gradle将AAR文件发布到JFrog工件。 一旦有了AAR文件并执行构建任务,发布就可以按预期工作了,问题是,如果AAR文件不存在,则无法作为构建过程的一部分来完成。
我想在有新文件发布时发布AAR文件。我尝试将assembleIntegrated.finalizedBy(artifactoryPublish)放进去,但这没有帮助。 在生成AAR之前会触发发布任务。
mygradle.gradle->
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
File AARFile1 = file("$buildDir/outputs/aar/my_aar_file1.aar")
File AARFile2 = file("$buildDir/outputs/aar/my_aar_file2.aar")
publishing {
publications {
AAR1(MavenPublication) {
groupId repoFolder
version libVersion
// Tell maven to prepare the generated "*.aar" file for publishing
if (AARFile1.exists()) {
artifactId libRelease
artifact(AARFile1)
} else {
println 'AAR1 files not found in' + AARFile1.absolutePath
}
}
AAR2(MavenPublication) {
groupId repoFolder
version libVersion
// Tell maven to prepare the generated "*.aar" file for publishing
if (AARFile2.exists()) {
artifactId libDebug
artifact(AARFile2)
} else {
println 'AAR2 files not found in' + AARFile2.absolutePath
}
}
}
}
artifactory {
contextUrl = "https://bintray.com/jfrog/artifactory:8080"
publish {
repository {
// The Artifactory repository key to publish to
repoKey = 'my_key'
username = 'my_username'
password = 'my_encrypt_password'
}
defaults {
// Tell the Artifactory Plugin which artifacts should be published to Artifactory.
if (AARFile1.exists() || AARFile2.exists()) {
publications('AAR1', 'AAR2')
publishArtifacts = true
// Properties to be attached to the published artifacts.
properties = ['qa.level': 'basic', 'dev.team':'Me' ]
// Publish generated POM files to Artifactory (true by default)
publishPom = true
}
}
}
}
我看到gradle任务列表如下:
executing tasks: [assembleIntegrated]
AAR1 files not found in /myfolder/.../my_lib_project/app/build/outputs/aar/my_aar_file1.aar
AAR2 files not found in /myfolder/.../my_lib_project/app/build/outputs/aar/my_aar_file2.aar
.
.
.
> Task :app:preBuild UP-TO-DATE
> Task :app:test UP-TO-DATE
> Task :app:check
> Task :app:build
> Task :app:artifactoryPublish
> Task :artifactoryDeploy
答案 0 :(得分:0)
发生这种情况是因为您将文件手动添加到了Maven发布中。当运行maven发布时,这些文件不存在。因此,您应该手动配置任务依赖性。当您将发布添加到项目中时,Gradle将结合发布名称和存储库名称生成一些任务。诸如此类:publish{publicationName}PublicationTo{RepositoryName}Repository
。因此,您应该将这些任务设置为取决于assembleIntegration
任务。
或者您可以使用android-maven-publish插件,该插件会自动完成此工作。