7/19/2017

JFrog setup gradle artifacts

Run JFrog

Create a directory which stores JFrog's persistent data, then run JFrog using Docker. We change the PORT to 8085 instead of using 8081 because 8081 port was occupied by my Jenkins server.
$ mkdir -p jfrog_data 
$ docker run --name jfrogartifactory -d -v jfrog_data:/var/opt/jfrog/artifactory -p 8085:8081 docker.bintray.io/jfrog/artifactory-oss
I created a makefile for running and stopping the container and backup data.
init:
 mkdir -p jfrog_data
run:
 docker run --name jfrogartifactory -d -v `pwd`/jfrog_data:/var/opt/jfrog/artifactory -p 8085:8081 docker.bintray.io/jfrog/artifactory-oss
stop:
 docker stop jfrogartifactory;docker rm jfrogartifactory
clean:
 rm -rf jfrog_data
 docker rmi -f docker.bintray.io/jfrog/artifactory-oss
backup:
 zip -r jfrog_data.zip jfrog_data
After running JFrog, you can check it by entering http://localhost:8085/

Create gradle and generic repositories


Create a group, permission, account




Log out of admin account

Publishing your library using Gradle

Step 1: Add org.jfrog.buildinfo:build-info-extractor-gradle:4.0.1 dependency to the project gradle
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.0.1"
    }
}
Also, add the variables to gradle.properities to let module use
artifactory_user=XXXX
artifactory_password=YYYY
artifactory_contextUrl=http://10.70.70.40:8085/artifactory

Step 2: Append the below snippet code to then end of your module's gradle file 

apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish' def libraryGroupId = 'AA.BB.CC' def libraryArtifactId = 'Test' def libraryVersion = '1.0.0' publishing { publications { aar(MavenPublication) { groupId libraryGroupId version libraryVersion artifactId libraryArtifactId artifact("$buildDir/outputs/aar/${artifactId}-release.aar") } } } artifactory { contextUrl = "${artifactory_contextUrl}" publish { repository { repoKey = 'gradle-release-local' username = "${artifactory_user}" password = "${artifactory_password}" } defaults { publications('aar') publishArtifacts = true properties = ['qa.level': 'basic', 'q.os': 'android', 'dev.team': 'core'] publishPom = true } } }

Go to command line to publish your module to your private JFrog artifactory
$ ./gradlew assembleRelease artifactoryPublish
Then, your artifacts will be located at http://localhost:8085/artifactory/webapp/builds/

Import the library in other projects

Step 1: Add repository dependency

    repositories {
        jcenter()
        maven {
            url "http:/[IP]:8085/artifactory/gradle-release-local"
        }
    }
Step 2: Import the library in your module and compile it
compile "com.pakcage:module:version"
It's done!


Upload other artifact using JFrog

Jfrog with free version supports that you can create a generic version and upload anything

Then, you can use curl command to push your artifact to that. Ex:
curl -u<USERNAME>:<PASSWORD> -T <PATH_TO_FILE> "http://10.70.70.44:8085/artifactory/<REPO KEY>/<TARGET_FILE_PATH>


My makefile file : https://github.com/tzutalin/docker/tree/master/JFrog

No comments:

Post a Comment