Reputation: 121
I have an Android library project and I am trying to publish the AAR files to JFrog artifactory using gradle. Once I have the AAR files and when I execute the build task, the publish is working as expected, the problem is that I am not able to do it as part of my build process if the AAR files are not there.
I want to publish the AAR files when ever a new one is available. I tried to put assembleIntegrated.finalizedBy (artifactoryPublish), but that didn’t help. The publish task gets triggered before the AARs are generated.
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
}
}
}
}
I see the gradle tasks list as below:
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
Upvotes: 0
Views: 536
Reputation: 723
It happens, because you add files manually to the maven publication. When maven publish runs, these files are not exists. So, you should configure task dependencies manually. When you add a publication to your project, Gradle will generate some tasks with combination of your publication names, and repo names. Something like that: publish{publicationName}PublicationTo{RepositoryName}Repository
. Thus, you should setup these task to depends on assembleIntegration
task.
Or you can use android-maven-publish plugin, which do this work automatically.
Upvotes: 0