How to add artifactory libs inside gradle? - android

I need to configure artifactory inside gradle (android app).
I already put all the script below inside build.gradle:
buildscript {
repositories {
jcenter()
maven {
url '.../artifactory/plugins-releases'
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.4.14"
}
}
apply plugin: "com.jfrog.artifactory"
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
artifactory {
contextUrl = "${artifactory_contextUrl}" //The base Artifactory URL if not overridden by the publisher/resolver
publish {
repository {
repoKey = 'libs-releases-local'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
resolve {
repository {
repoKey = 'libs-releases'
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
}
When I try to compile a lib from this artifactory, I get this error:
Failed to resolve: my-lib:1.0.0

The com.jfrog.artifactory plugin is for publishing into artifactory, not for using it. If you want to use it, you need to define it as repository for your build.

I had a similar issue. For me, it was that the maven { url "" } value needed to start with "http://". So for exmaple
maven {
url 'http://.../artifactory/plugins-releases'
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}

Related

How to use Jfrog Artifactory packages in an gradle file in an android project

I have uploaded a few binary files in maven format to the jfrog artifactory, but could not seem to be able to resolve them in my project. This is what I am essentially doing,
build.gradle(app)
implementation 'io.sariska:sariska-media-transport:5.0.9'
build.gradle (project level)
allprojects {
apply plugin: 'maven-publish'
repositories {
google()
jcenter()
maven {
url = "https://sariska.jfrog.io/artifactory/sariska-media-libs-release-local/"
}
}
}
Am I missing something here?
Well , in my situation
I have declared a mavenRepoURL like this
mavenRepoURL = "https:link/to/artifactory"
Then I repositories section I have added
maven {
url = mavenRepoURL
credentials {
username artifactoryUser
password artifactoryPwd
}
}
and the artifactoryUser and artifactoryPwd either hardcoded or get from proeties or environment variables with this function
artifactoryUser = getConfigurationProperty("ARTIFACTORY_USER", "artifactoryUser", null)
artifactoryPwd = getConfigurationProperty("ARTIFACTORY_PWD", "artifactoryPwd", null)
String getConfigurationProperty(String envVar, String sysProp, String defaultValue) {
def result = System.getenv(envVar) ?: project.findProperty(sysProp)
result ?: defaultValue
}
This wat I can add to my dependencies like maven central
implementation "name:ImportJava:1.2.1-SNAPSHOT"

Jfrog artifactory, how to download/implement a dependency

I have JFrog Open Source installed on a server and upload an android aar library by hand.
In the gradle file, I set up a configuration like this.
buildscript {
dependencies { classpath "org.jfrog.buildinfo:build-info-extractor-gradle:latest.release" }
repositories {
maven {
credentials {
username = artifactory_username
password = artifactory_password
}
url "https://.../artifactory/libs-release"
}
}
}
allprojects{
apply plugin: org.jfrog.gradle.plugin.artifactory.ArtifactoryPlugin
artifactory {
resolve {
contextUrl = "https://.../artifactory"
repoKey = 'libs-global'
username = artifactory_username
password = artifactory_password
}
}
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:latest.release"
}
}
apply plugin: "com.jfrog.artifactory"
QUESTION:
How can download or implement my aar libary in the android project?
Example:
implementation 'com.google.code.gson:gson:2.8.6'
You need to add your Jfrog in build.gradle(project) like this:
allprojects {
repositories {
...
maven {
url("https://your-url.jfrog.com/more/path")
}
google()
jcenter()
...
}
}
Then you just add your dependency in dependencies.

Artifactory upload missing modules

i try to upload an .aar file to an Artifactory Server. Im using artifactoy plugin :
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.6.1'
classpath 'com.github.ben-manes:gradle-versions-plugin:0.13.0' // version plugin support
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
//Check for the latest version here: http://plugins.gradle.org/plugin/com.jfrog.artifactory
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.4.5"
}
}
I read quite a lot of documentation last 2 days and cant figure out why the following is not working:
First of all i do not understand how the artifactory plugin decides which repository it should take to upload the *.aar file ?
In Artifactory are two kind of endpoint to upload for internal use: lib-release-local and lib_snapshot
In my build.gradle in project root i define them:
allprojects {
apply plugin: "com.jfrog.artifactory"
repositories {
jcenter()
maven { url "https://jitpack.io" }
mavenLocal()
mavenCentral()
maven {
url 'https://servername/artifactory/libs-release-local'
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
maven {
url 'https://servername/artifactory/libs-snapshot'
credentials {
username = "${artifactory_user}"
password = "${artifactory_password}"
}
}
}
}
artifactoryPublish.skip = true
artifactory {
contextUrl = "${artifactory_contextUrl}"
publish {
repository {
repoKey = 'libs-release-local'
username = "${artifactory_user}"
password = "${artifactory_password}"
}
defaults {
publications('aar')
publishArtifacts = true
properties = ['qa.level': 'basic', 'dev.team': 'core']
publishPom = true
}
}
}
My Second Problem is that Artifactory Plugin uploads something, i see this log entry:
Deploying build descriptor to: https://servername/artifactory/api/build
Build successfully deployed. Browse it in Artifactory under https://servername/artifactory/webapp/builds/eap-androidcore/1475772844540
On the Artifactory Web UI I see only something got uploaded in the "Build Browser". There are no modules listed, the *.aar file is missing. Also no POM gets generated at all like in any other maven repositories.
publishing {
publications {
aar(MavenPublication) {
groupId = 'com.example.core'
artifactId project.name
version = VERSION_NAME
artifact "${project.buildDir}/build/outputs/aar/core_icons-debug.aar"
}
}
}
I checked the path to the file couple of times, it's correct.
So why does artifactory not upload the .aar file ?
Many thanks for reading/helping me

implement maven artifact with additional properties in gradle

In my pom file I have one artifact like below:
<artifactItem>
<groupId>com.xyz</groupId>
<artifactId>xyz.abc</artifactId>
<version>1.0</version>
<classifier>pqr</classifier>
<type>js</type>
<overWrite>true</overWrite>
<outputDirectory>/opt/test</outputDirectory>
<destFileName>test.js</destFileName>
</artifactItem>
How to implement this in my build.gradle. I am using gradle 2.6.
Sorry, I cannot post original code so put some unrealistic values. Please reply
WIth gradle you can use the maven plugin.
You can find the full doc for the 2.6 here.
I don't know if you can set all attributes, but you can use a script like this:
apply plugin: 'maven'
apply plugin: 'signing'
afterEvaluate { project ->
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
pom.groupId = GROUP
pom.artifactId = POM_ARTIFACT_ID
pom.version = VERSION_NAME
repository(url: "...") {
authentication(userName: "user", password: "pass")
}
snapshotRepository(url: "...") {
authentication(userName: "user", password: "pass")
}
pom.project {
name POM_NAME
packaging POM_PACKAGING
description POM_DESCRIPTION
url POM_URL
scm {
url POM_SCM_URL
connection POM_SCM_CONNECTION
developerConnection POM_SCM_DEV_CONNECTION
}
licenses {
license {
name POM_LICENCE_NAME
url POM_LICENCE_URL
distribution POM_LICENCE_DIST
}
}
developers {
developer {
id POM_DEVELOPER_ID
name POM_DEVELOPER_NAME
}
}
}
}
}
}
signing {
required { true }
sign configurations.archives
}
artifacts {
archives xxxx
}
}
i created a gradle task
task test <<{
copy {
from --dir---
into --dir--
rename { String fileName ->
fileName.replace("xyz.abc-$1.0-pqr","user-prefs")
}
}
}
It worked for me.

Gradle publish to the specific repo of the Artifactory

I am trying to setup the artifacts (APK/aar files) build process with gradle similar to how I am used to with maven.
mvn release:prepare (Adjusts version, checks into SVN, creates the tag)
mvn release:perform -Dgoals=deploy (Pushes the artifact to http://artifactory.XXX.local/artifactory/libs-releases-local/)
I want to be able to run the gradle commands and achieve similar results. I am using https://github.com/researchgate/gradle-release plugin for the release management (which works fine so I am good with release). But when I run the command gradlew artifactoryPublish the artifact is deployed at some other location (as if it's not respecting the repoKey in the gradle file)
D:\my-lib-android-0.0.2>gradlew artifactoryPublish ... ... [buildinfo]
Not using buildInfo properties file for this build.
:artifactoryPublish Deploying build descriptor to:
http://artifactory.XXX.local/artifactory/api/build Build successfully
deployed. Browse it in Artifactory under
http://artifactory.XXX.local/artifactory/webapp/builds/my-lib-android-0.0.2/1449880830949>
BUILD SUCCESSFUL
Total time: 9.692 secs
So my question is how can I fix my setup so that the artifact is pushed to a URL similar to this:
http://artifactory.XXX.local/artifactory/libs-releases-local/com/example/my-lib-android/0.0.2/my-lib-android-0.0.2.aar
build.gradle File:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
classpath(group: 'org.jfrog.buildinfo', name: 'build-info-extractor-gradle', version: '3.1.2')
classpath 'net.researchgate:gradle-release:2.3.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
plugins {
id 'net.researchgate.release' version '2.3.4'
}
apply plugin: "com.jfrog.artifactory"
apply plugin: 'maven-publish'
apply plugin: 'net.researchgate.release'
allprojects {
repositories {
jcenter()
maven {
url 'http://artifactory.XXX.local/artifactory/libs-releases-local'
}
}
}
artifactory {
contextUrl = "${artifactory_contextUrl}"
//The base Artifactory URL if not overridden by the publisher/resolver
publish {
repository {
repoKey = "libs-releases-local"
username = "${artifactory_user}"
password = "${artifactory_password}"
maven = true
}
}
}
release {
revertOnFail = false
}
task build{
}
gradle.properties File:
version=my-lib-android-0.0.3-SNAPSHOT
artifactory_user=myUserName
artifactory_password=myPasssword
artifactory_contextUrl=http://artifactory.XXX.local/artifactory
Using android-maven plugin:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.9.2'
classpath 'com.github.dcendents:android-maven-plugin:1.0'
classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:3.2.0'
}
}
apply plugin: 'android-library'
apply plugin: 'com.jfrog.artifactory-upload'
apply plugin: 'android-maven'
configurations {
published
}
task sourceJar(type: Jar) {
from android.sourceSets.main.java
classifier "sources"
}
artifactoryPublish {
dependsOn sourceJar
}
artifacts {
published sourceJar
}
artifactory {
contextUrl = "${artifactory_contextUrl}"
publish {
repository {
repoKey = "libs-releases-local"
username = "${artifactory_user}"
password = "${artifactory_password}"
}
defaults {
publishConfigs('archives', 'published')
publishPom = true //Publish generated POM files to Artifactory (true by default)
publishIvy = false //Publish generated Ivy descriptor files to Artifactory (true by default)
}
}
}
I usually do it with the mavenDeployer-plugin like this.
Don't know if it matches your case, but I'll just leave it here.
apply plugin: 'maven'
uploadArchives {
repositories {
mavenDeployer {
repository(url: 'http://arandom.nexus.com:8081/nexus/content/repositories/releases') {
authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD);
}
snapshotRepository(url: 'http://arandom.nexus.com:8081/nexus/content/repositories/snapshots') {
authentication(userName: NEXUS_USERNAME, password: NEXUS_PASSWORD);
}
pom.groupId = "groupId"
pom.artifactId = "artifactId"
pom.version = "${versionMajor}.${versionMinor}.${versionPatch}"
}
}
}
some further reading for local repos here

Categories

Resources