Gradle publish to the specific repo of the Artifactory - android

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

Related

How do I publish subproject to Maven with subprojects buildscript gradle version?

I want to publish some subproject to maven by using maven-publish plugin. The current Gradle script looks like this.
apply plugin: 'maven-publish'
group "com.huawei.quickapp"
version "1.0-SNAPSHOT"
publishing {
publications {
publishTask(MavenPublication) {
}
}
repositories {
maven {
url = uri("${rootDir}/local_repo/repos/")
}
}
}
}
static Boolean publishIfNeeded(taskName){
println("name = " + taskName)
def list = ["baselibrary", "corelibrary"]
if (taskName in list) {
return true
}
return false
}
I just want two libraries,core and base to be published. When I submitted the code to the pipeline, the CI suggested that the NDK version did not match, but there was no NDK-related configuration in my code. The upgrade is necessary because only versions greater than 3.6 support the use of From Components.Debug or some other build variable in gradle script.I tried configuring the build script for Subproject separately like this:
buildscript {
ext.kotlin_version = "1.4.21"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:3.5.3"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
subprojects {
buildscript {
ext.kotlin_version = "1.4.21"
repositories {
google()
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.1"
}
}
}
but it still not work. I got this error
Could not get unknown property 'Debug' for SoftwareComponentInternal set of type org.gradle.api.internal.component.DefaultSoftwareComponentContainer.
Is there a way to publish a submodule using the buildScripte of a submodule? thx.

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

Publish android library to jcenter: gradle bintrayUpload does not find libraries

I'm trying to publish an Android library to jcenter. I've followed https://github.com/danielemaddaluno/gradle-jcenter-publish tutorial. Everything works fine until I try to execute
gradle bintrayUpload
When I do so I get a BUILD FAILED. When I look into the errors I see
package com.android.volley does not exist
Therefore the libraries that I have included as a gradle dependency are not being found
dependencies {
compile 'com.mcxiaoke.volley:library:1.+' (...)
}
The same happends with other libraries included.
How can I fix this problem?
I Attach the module build.gradle
apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: "com.jfrog.bintray"
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
minSdkVersion 8
targetSdkVersion 22
versionCode 1
versionName "0.0.1"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile 'com.mcxiaoke.volley:library:1.+'
compile 'com.shamanland:fab:0.0.8'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.android.support:appcompat-v7:22.0.0'
compile 'com.android.support:gridlayout-v7:21.0.3'
}
def siteUrl = "SOME_URL"
def gitUrl = 'SOME_URL'
group = "GROUP_ID"
install {
repositories.mavenInstaller {
// This generates POM.xml with proper parameters
pom {
project {
packaging 'aar'
// Add your description here
name 'NAME'
description = 'DESCRIPTION'
url siteUrl
// Set your license
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id 'MY_ID'
name 'MY_NAME'
email 'MY_EMAIL'
}
}
scm {
connection gitUrl
developerConnection gitUrl
url siteUrl
}
}
}
}
}
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
artifacts {
archives javadocJar
archives sourcesJar
}
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
// https://github.com/bintray/gradle-bintray-plugin
bintray {
user = properties.getProperty("bintray.user")
key = properties.getProperty("bintray.apikey")
configurations = ['archives']
pkg {
repo = "maven"
// it is the name that appears in bintray when logged
name = "androidupdatechecker"
websiteUrl = siteUrl
vcsUrl = gitUrl
licenses = ["Apache-2.0"]
publish = true
version {
gpg {
sign = true //Determines whether to GPG sign the files. The default is false
passphrase = properties.getProperty("bintray.gpg.password") //Optional. The passphrase for GPG signing'
}
// mavenCentralSync {
// sync = true //Optional (true by default). Determines whether to sync the version to Maven Central.
// user = properties.getProperty("bintray.oss.user") //OSS user token
// password = properties.getProperty("bintray.oss.password") //OSS user password
// close = '1' //Optional property. By default the staging repository is closed and artifacts are released to Maven Central. You can optionally turn this behaviour off (by puting 0 as value) and release the version manually.
// }
}
}
}
and the project build.gradle
// 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.1.2'
classpath 'com.github.dcendents:android-maven-plugin:1.2'
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.1"
}
}
allprojects {
repositories {
jcenter()
}
}
The library is in maven repository, so you need to declare the maven central repository. Add it in your project build.gradle file like this:
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.2'
classpath 'com.github.dcendents:android-maven-plugin:1.2'
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.1"
}
}
Please refer to the following:
user = properties.getProperty("bintray.user")
key = properties.getProperty("bintray.apikey")
At this point, you need in your local. Join in the properties files,
Bintray. User = XXX
Bintray apikey = XXX

Is it possible to have a plain java library module depending on android SDK in Android Studio

In my multi-module Android Studio project, I would like to create a plain java module. But in that module, I also want to be able to use certain Android API. Is this possible? If yes, how should build.gradle look like?
Thanks
jia
As long as the Android functionality that you need is in a jar instead of an aar, then you should be able to do this fairly easily as my team has a couple of artifacts like this. For Android jar artifacts in Maven Central, you just need to add the dependency:
compile 'com.google.android:android:4.1.1.4'
If the functionality is in one of the artifacts installed via the Android SDK Manager, then you can just add the dependency as above, but you'll need to add the local Android repo to pull the artifacts:
maven { url "file:///${System.env.ANDROID_HOME}/extras/android/m2repository" }
Edit
Also forgot to mention, you'll want to mark the Android artifacts as provided so that you don't get dependency clashes. You can do that by using the following:
configurations {
provided
compile.extendsFrom provided
}
dependencies {
provided('com.google.android:android:4.1.1.2')
}
Let me know if you need an example build.gradle and I will add one.
Edit 2
Below is an example build.gradle that we use for one of our projects.
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'pmd'
apply plugin: 'jacoco'
apply plugin: 'findbugs'
apply plugin: 'project-report'
apply plugin: 'jxr'
group = 'com.example'
archivesBaseName = 'project-name'
version = '1.0.0-SNAPSHOT'
sourceCompatibility = 1.7
configurations {
provided
compile.extendsFrom provided
}
buildscript {
repositories {
maven { url 'http://repo1.maven.org/maven2/' }
maven { url "http://jcenter.bintray.com" }
}
dependencies {
classpath('net.davidecavestro:gradle-jxr-plugin:0.1')
}
}
repositories {
mavenCentral()
if (project.hasProperty("mavenLocal")) {
maven { url "${System.env.HOME}/.m2/repository" }
}
maven { url "file:///${System.env.ANDROID_HOME}/extras/android/m2repository" }
}
dependencies {
compile('com.google.code.findbugs:annotations:2.0.2')
compile('com.google.code.gson:gson:2.2.4')
compile('com.google.guava:guava:15.0')
provided('com.google.android:android:4.0.1.2')
testCompile('commons-io:commons-io:2.4')
testCompile('junit:junit:4.11')
testCompile('org.robolectric:robolectric:2.3')
testCompile('org.mockito:mockito-all:1.10.8')
}
test {
dependsOn ':assemble'
testLogging {
showExceptions = true
showStackTraces = true
exceptionFormat = "full"
events "passed", "skipped", "failed"
}
}
javadoc {
source = sourceSets.main.allJava
classpath = test.classpath
}
jacocoTestReport {
dependsOn test
description = "Generate Jacoco coverate reports after running tests."
reports {
xml.enabled false
csv.enabled false
html.destination "${buildDir}/reports/jacoco"
}
}
pmd.ignoreFailures = true
pmdTest.enabled = false
pmdMain.enabled = true
pmdMain {
reports {
xml.enabled = false
html.enabled = true
}
}
findbugs.ignoreFailures = true
findbugs.excludeFilter = file('./findbugs-exclude-filter.xml')
findbugsTest.enabled = false
findbugsMain.enabled = true
findbugsMain {
reports {
xml.enabled = false
html.enabled = true
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.1'
distributionUrl = "http://services.gradle.org/distributions/gradle-${gradleVersion}-all.zip"
}
task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar) {
classifier = 'javadoc'
from "${projectDir}/build/docs"
}
artifacts {
archives sourcesJar
archives javadocJar
}
uploadSite.dependsOn(':check')
check.dependsOn('sourcesJar')
check.dependsOn('javadoc')
check.dependsOn('jacocoTestReport')
check.dependsOn('projectReport')
check.dependsOn('jxr')

Categories

Resources