gradle snapshot not resolved in local repository when uniqueVersion=false - android

For my Android Library I'm using the "UploadArchives" task to deploy the AAR :
uploadArchives {
repositories.mavenDeployer {
configuration = configurations.deployLibrary
pom.groupId = groupId
pom.artifactId = artifactId
pom.version = version
uniqueVersion = false
repository(url: "${RemoteReleaseDest}")
snapshotRepository(url: 'file://' + "${localReleaseDest}") { }
}
}
Where "RemoteReleaseDest" is a remote Repository and "localReleaseDest" point to my Local maven repository (C:/User/me/.m2.repository).
this work pretty well for release version ex: myaar:2.0.0 ( I can as well set the "RemoteReleaseDest" to my local .m2 repository to force to deploy the release on it.
Then when I configure the dependency in my android project like this :
compile 'mygroupId:myartefact:2.0.0'
the dependency is correctly resolved (even from my local repository).
but if I try with snaptshot :
compile 'mygroupId:myartefact:2.0.0-SNAPSHOT'
gradle cannot resolve the dependency. while in the gradle log I can see that it is seaching in my .m2 local repository.
But if I Upload the snapshot archives with the parameter :
uniqueVersion = true
the gradle can resolve the dependency !
The problem in this case is that every time I launch the task "uploadArchives" I will create new AAR, xml, md5 etc... files under the local SNAPSHOT directory.
So why gradle cannot resolve the snapshot dependency when the snapshot is deployed with the param uniqueVersion = falseand how can I manage this issue ?

Related

Use maven-publish to publish Android apk and aar with build variant (Android Gradle plugin 4.0)

I'm trying to follow https://developer.android.com/studio/build/maven-publish-plugin to publish library (aar) module and application (apk) module to Maven repository (maven-publish plugin). I'm using Kotlin Gradle kts instead of Grovy.
Sample publish in Grovy (from link above)
publishing {
publications {
paidRelease(MavenPublication) {
// The following applies a component to this publication
// which results in publishing an app bundle.
from components.paidRelease_aab
groupId = 'com.example.MyApp'
artifactId = 'paid-release-aab'
version = '1.0'
}
paidDebug(MavenPublication) {
// The following applies a component to this publication
// which results in publishing APKs in a ZIP file.
from components.paidDebug_apk
groupId = 'com.example.MyApp'
artifactId = 'paid-debug-apks'
version = '1.0'
}
}
}
My kotlin dls publishing code for app module
publications {
create<MavenPublication>("mastercardMavenApk") {
groupId = ProjectInfo.groupId
artifactId = ProjectInfo.artifactId
version = ProjectInfo.nexusVersion + if (useReleaseRepo) "" else "-SNAPSHOT"
from(components["mastercardDebug_apk"])
}
}
where mastercardDebug is one of my Active Build Variant
I always have below error:
SoftwareComponentInternal with name 'mastercardDebug_apk' not found
What should be the correct way to use maven-publish plugin for Android project (support both aar and apk module)?
just use print(components.names) before from(components["mastercardDebug_apk"])
to verify that the component exsists. maybe its just a typo

maven-publish plugin gradle only publish specific module

I'm developing a multi-module android project using gradle build.
I'm using maven-publish plugin to publish artifact to sonartype nexus.
The current setup is inside every module there is a publication job
plugins{
id(Plugins.kotlinAndroidApplication)
id(Plugins.kotlinAndroid)
id(Plugins.kotlinAndroidExtensions)
id(Plugins.mavenPublish)
id(Plugins.dokkaAndroid)
}
publishing {
repositories {
maven {
credentials {
username = project.properties["mavenUser"] as? String
password = project.properties["mavenPassword"] as? String
}
url = https://mynexus
}
}
publications {
create<MavenPublication>("mavenAar") {
groupId = rootProject.extra.get("groupId") as String
artifactId = rootProject.extra.get("artifactId") as String
version = (rootProject.extra.get("versionName") as String) + (if (project.hasProperty("release")) "" else "-SNAPSHOT")
from(components["android"])
//artifact(tasks["javadocJar"])
artifact(tasks["dokkaJar"])
}
}
}
When my Jenkin CI build the project with deploy = true, every module will be published. The problem is some module depend on other, so the dependency module will be published twice. Re-deploy module with same version is not allowed on release nexus maven repo.
Anyway to only publish certain module only or to ensure every module is only deploy once?

HTTP/1.1 401 Unauthorized when uploading binary on bintray

I'm trying to upload a android library module from android studio,
followed by this blog: https://inthecheesefactory.com/blog/how-to-upload-library-to-jcenter-maven-central-as-dependency/en
(1)
./gradlew install
Result:- BUILD SUCCESSFUL
(2)
./gradlew build bintrayUpload
Result:- Getting below error-
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':acr:bintrayUpload'.
Could not create version '1.0.0': HTTP/1.1 401 Unauthorized [message:This resource requires authentication]
I checked many times and sure my username and apikey is correct.
(In username i'm using organization name instead of bintray username because my repository is created under organization).
If anyone has an idea, I would appreciate the help :)
In Bintray your username must be the username of your user account and not the Organisation.
If you are the owner of the repo then the permission mechanism will allow the action.
In username i'm using organization name
Some documentation links:
https://github.com/bintray/gradle-bintray-plugin#readme
https://bintray.com/docs/usermanual/formats/formats_mavenrepositories.html#_working_with_gradle
EDIT:
Make sure you are using the userOrg parameter, since your repo is under the organization subject and not under the user.
check step 4 here:
https://github.com/bintray/gradle-bintray-plugin#step-4-add-your-bintray-package-information-to-the-bintray-closure
Here is a working build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
}
}
plugins {
id "com.jfrog.bintray" version "1.7"
}
apply plugin: 'com.jfrog.bintray'
apply plugin: 'java'
bintray {
user = 'myuserusername'
key = '**********'
pkg {
repo = 'gradlerepo'
name = 'gradlepackage'
userOrg = 'myorgname'
version {
name = '1.0-Final'
}
}
}
I would like to add more to #gba's answer here
Instead of directly including your bintray username and apikey, you should include them in local.properties file at root of your project. The local.properties file is by default added to .gitignore and hence not uploaded to githup with other files. It helps in keeping your username and apikey safe.
bintray.user=<your bintray username>
bintray.apikey=<your bintray apikey>
Then in your module gradle file add:
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
bintray {
user = properties.getProperty("bintray.user")
key = properties.getProperty("bintray.apikey")
configurations = ['archives']
pkg {
repo = "maven"
name = "<Your library name>"
websiteUrl = <your siteUrl>
vcsUrl = gitUrl
licenses = ["Apache-2.0"]
publish = true
}
}
Reference: https://www.virag.si/2015/01/publishing-gradle-android-library-to-jcenter/

How to change groupid if project is already uploaded to bintray and synced with jcenter?

I've recently uploaded my github project to bintray and successfully synced it with JCenter repository.
I used this tutorial:
http://inthecheesefactory.com/blog/how-to-upload-library-to-jcenter-maven-central-as-dependency/en
So my gradle dependency was :
dependencies {
compile 'com.github.danylo2006:hashtag-helper:1.1.0'
}
In order to upload it I've modified my build.gradle and added relevant peace of script. Everything like in the tutorial.
... some code here
ext {
bintrayRepo = 'maven'
bintrayName = 'hashtag-helper'
publishedGroupId = 'com.github.danylo2006'
libraryName = 'HashTagHelper'
artifact = 'hashtag-helper'
libraryDescription = 'This is a library designed for highlighting hashtags ("#example") and catching click on them.'
siteUrl = 'https://github.com/danylo2006/HashTagHelper'
gitUrl = 'https://github.com/danylo2006/HashTagHelper.git'
libraryVersion = '1.1.0'
developerId = 'danylovolokh'
developerName = 'Danylo Volokh'
developerEmail = 'v.danylo#gmail.com'
licenseName = 'The Apache Software License, Version 2.0'
licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
allLicenses = ["Apache-2.0"]
}
Here is the tricky part:
I've changed my github nickname danylo2006 to danylovolokh and now I want to change gradle dependency:
dependencies {
compile 'com.github.danylo2006:hashtag-helper:1.1.0'
}
Change to:
dependencies {
compile 'com.github.danylovolokh:hashtag-helper:1.1.0'
}
I got groupId that I need from Sonatype
So I've modified my gradle script.
The only relevant change is :
publishedGroupId = 'com.github.danylo2006'
Has been changed to
publishedGroupId = 'com.github.danylovolokh'
I run the relative commands:
gradlew install
gradlew bintrayUpload
And I got BUILD_SUCCESSFULL
But if I add new dependency to any other gradle project I get an error that "Error:(36, 13) Failed to resolve: com.github.danylovolokh:hashtag-helper:1.1.0"
Inclusion to JCenter is done by the path of your groupId. JFrog needs to include the new path from your package to JCenter as well.
Please contact JFrog support at support#bintray.com
#JBaruch is correct. It seems that emailing bintray is the correct way to really get these things changed. But for completeness, I am attaching the response I received from Bintray. Hopefully posting their response will prevent them from getting bombarded by emails...
For context, I have a java repository with the package (groupID:artifact):
io.jeti.utils:serialize
There are currently versions (1.0.0/1.0.1/1.0.2/1.0.3/1.0.4/) using this groupID. I asked them to change this to
io.jeti:serialize
And in fact, I already pushed versions (1.0.5/1.0.6) to bintray with this shortened groupID. This was the response:
We understand your use case. In such cases, we recommend creating a
new package and submit a new inclusion request. Please let me explain,
let's take 'serialize' package from your java repo for example.
Currently it has 2 path prefixes when only one is synced with Jcenter:
io/jeti/utils/serialize/ -> Synced io/jeti/serialize -> doesn't exist
in jcenter
Relinking the new groupId, will cause the old/current groupId
(io/jeti/utils) and its versions (1.0.0/1.0.1/1.0.2/1.0.3/1.0.4/) to
be un-resolvable when since it rely on the old groupId. This might
broke current integrations with your builds and scripts. Therefore,
the best approach is to create a new package (e.g serialize2), submit
a new inclusion request (which includes the new groupId -
io/jeti/serialize) and we will approve it and make it synced with
JCenter. In this case, you will get a full resolution of all of your
existing versions of the package (as well as 1.0.5/1.0.6).
Please let us know how to proceed.
My painfully acquired advice would be to create a new bintray package and ask for that to be published to the new groupId. I have tried to move an existing package and 48 hours and 20 messages to and from JFrog support have left me unable to publish my original package at the old or new location, nor a new package at the new location.
In the end I have had to register a new domain name to host my project, as bintray have effectively denied access to the groupId I was trying to change to.

How to run a unit test task before uploadArchives

I've got this config to upload artifact to local maven repository.
uploadArchives {
repositories {
mavenDeployer {
pom {
groupId = 'group'
artifactId = 'android'
version = android.defaultConfig.versionName
}
repository(url: 'file://' + new File(System.getProperty('user.home'), '.m2/repository').absolutePath)
}
}
}
I want it to run all the unit tests before uploading the artifact. I'm tired of running the unit tests task manually every time, so I thought uploadArchives task should depend on testDebugUnitTest. The test tasks comes from Android library plugin.
uploadArchives {
dependsOn testDebugUnitTest
}
Unfortunately this configuration doesn't work. Is it possible to configure it the way I want?
I do this to automate my tests. The basic syntax here is <your task> dependsOn '<this task>' in order for your entire build process to finish successfully.
You want something like this:
uploadArchives.dependsOn 'testDebugUnitTest'

Categories

Resources