This article explains how to publish artifacts along with build info from a Gradle Android project, and the mandatory things you’ll need to include in the build.gradle,gradle-wrapper.properties file.
- Execute a Git clone in your client machine from here
- In the gradle-android example HERE, make sure the following settings are in place before running the gradle publish command.
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { google() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:3.6.3' classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:4.15.2' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { apply plugin: 'com.jfrog.artifactory' apply plugin: 'maven-publish' // apply plugin: 'java' repositories { google() mavenCentral() } } artifactoryPublish.skip = true project('app') { artifactoryPublish.dependsOn('build') publishing { publications { app(MavenPublication) { // from components.java groupId = group artifactId = project.getName() version = currentVersion artifact("$buildDir/outputs/apk/release/app-release-unsigned.apk") } } } artifactoryPublish { publications(publishing.publications.app) } } project('library') { artifactoryPublish.dependsOn('build') publishing { publications { aar(MavenPublication) { // from components.java groupId = group artifactId = project.getName() version = currentVersion // Tell maven to prepare the generated "*.aar" file for publishing artifact("$buildDir/outputs/aar/${project.getName()}-release.aar") } } } artifactoryPublish { publications(publishing.publications.aar) } } artifactory { clientConfig.setIncludeEnvVars(true) clientConfig.info.addEnvironmentProperty('test.adding.dynVar',new Date().toString()) contextUrl = 'http://localhost:8081/artifactory'; publish { repository { repoKey = 'libs-snapshot-local' // The Artifactory repository key to publish to username = "admin" // The publisher user name password = "password1" // The publisher password // This is an optional section for configuring Ivy publication (when publishIvy = true). ivy { ivyLayout = '[organization]/[module]/ivy-[revision].xml' artifactLayout = '[organization]/[module]/[revision]/[module]-[revision](-[classifier]).[ext]' mavenCompatible = true //Convert any dots in an [organization] layout value to path separators, similar to Maven's groupId-to-path conversion. True if not specified } } defaults { // Reference to Gradle publications defined in the build script. // This is how we tell the Artifactory Plugin which artifacts should be // published to Artifactory. publications('app', 'aar') publishArtifacts = true // Properties to be attached to the published artifacts. properties = ['qa.level': 'basic', 'dev.team' : 'core'] publishPom = true // Publish generated POM files to Artifactory (true by default) } } } System.setProperty('javax.net.ssl.trustStore', 'cacerts') System.setProperty('javax.net.ssl.trustStorePassword', 'changeit')
In the gradle-wrapper.properties, the Gradle version has been changed to 6.4.
The following is the prerequisite to your $cat
gradle/wrapper/gradle-wrapper.properties:
#Sun Dec 03 11:42:26 IST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-6.4-all.zip
In the example above, the following were used:
- Gradle Build Tool v3.6.3 in build.gradle,
- JFrog’s Build Info Extractor v4.15.2 in build.Gradle, and
- Gradle Build Tool v6.4 in gradle-wrapper.properties
The following will be your $ ./gradlew clean artifactoryPublish command output:
> Task :app:lint Ran lint on variant release: 5 issues found Ran lint on variant debug: 5 issues found Wrote HTML report to file:///Users/amithkm/project-examples/gradle-examples/gradle-android-example/app/build/reports/lint-results.html Wrote XML report to file:///Users/amithkm/project-examples/gradle-examples/gradle-android-example/app/build/reports/lint-results.xml > Task :library:lint Ran lint on variant debug: 3 issues found Ran lint on variant release: 3 issues found Wrote HTML report to file:///Users/amithkm/project-examples/gradle-examples/gradle-android-example/library/build/reports/lint-results.html Wrote XML report to file:///Users/amithkm/project-examples/gradle-examples/gradle-android-example/library/build/reports/lint-results.xml [pool-65-thread-2] Deploying artifact: http://localhost:8081/artifactory/libs-snapshot-local/gradle-android-example/app/1.0-SNAPSHOT/app-1.0-SNAPSHOT.apk [pool-65-thread-3] Deploying artifact: http://localhost:8081/artifactory/libs-snapshot-local/gradle-android-example/library/1.0-SNAPSHOT/library-1.0-SNAPSHOT.aar [pool-65-thread-3] Deploying artifact: http://localhost:8081/artifactory/libs-snapshot-local/gradle-android-example/library/1.0-SNAPSHOT/library-1.0-SNAPSHOT.pom [pool-65-thread-2] Deploying artifact: http://localhost:8081/artifactory/libs-snapshot-local/gradle-android-example/app/1.0-SNAPSHOT/app-1.0-SNAPSHOT.pom > Task :artifactoryDeploy Deploying build descriptor to: http://localhost:8081/artifactory/api/build Build successfully deployed. Browse it in Artifactory under http://localhost:8081/artifactory/webapp/builds/gradle-android-example/1589806919408 Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0. Use '--warning-mode all' to show the individual deprecation warnings. See https://docs.gradle.org/6.4/userguide/command_line_interface.html#sec:command_line_warnings BUILD SUCCESSFUL in 9s 121 actionable tasks: 113 executed, 8 up-to-date