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/
Related
I have been using GitHub packages for a while, in an Android project, without having any issue.
Now when I try to publish a new package I get the error:
Could not PUT Received status code 422 from server: Unprocessable Entity
To be sure that I hadn't change anything I went back to a git-tag from which I successfully managed to publish a package a few days ago, I changed only the version to generate a different package. I get the same error.
I added logs and I can see that the token is read correctly, all the value (GROUP, VERSION, etc) seem correct and that the file that I'm trying to publish is there in the correct folder.
I have also tried to create and use a new token in case something was wrong with the old one but it didn't help.
Would GitHub reject the publishing with that error in case I published too many files? I did not find any documentation about the error that you get in that case.
EDIT
I have also tried to create a new project and post to that one, in case something had got messed up in the initial one, but it did not work either.
I have tried to PUT a file directly using CURL and this worked that means that the token is correct and that the problem is not the limit in the total size of the published packages:
curl -X PUT \
"https://maven.pkg.github.com/companyname/repositoryname/com/companyname/artifactid/v2.1.520/artifactid-v2.1.520.aar" \
-H "Authorization: token mytoken” \
--upload-file “/full/path/to/file.aar" -vvv
Of course, this is not the solutions since I need to post the maven repo with the pom etc.
END EDIT
Here my configuration that had been working for a long time and that is just following the documentation + the logs that I added to investigate the issue.
In the build.gradle:
allprojects {
repositories {
google()
jcenter()
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/companyname/companyname-android-sdk")
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("GitHubPackagesUsername")
password = project.findProperty("gpr.key") ?: System.getenv("GitHubPackagesToken")
println "GitHubPackages build.gradle\n\tusername=$username\n\ttoken=$password"
}
}
}
}
in the publish-artifacts.gradle:
publishing {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/companyname/companyname-android-sdk")
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("GitHubPackagesUsername")
password = project.findProperty("gpr.key") ?: System.getenv("GitHubPackagesToken")
println "GitHubPackages Publish Artifact:\n\tusername=$username\n\ttoken=$password"
}
}
}
publications {
gpr(MavenPublication) {
println "\tskSdkVersion=$SK_SDK_VERSION\n\tarchivesBaseName=$archivesBaseName\n\tGROUP=$GROUP\n\tdesciption=$POM_DESCRIPTION"
println "artifact from $buildDir/outputs/aar/$archivesBaseName-${VARIANT_SUFFIX}.aar"
groupId SK_GROUP
version SK_SDK_VERSION
artifactId archivesBaseName
artifact "$buildDir/outputs/aar/$archivesBaseName-${VARIANT_SUFFIX}.aar"
description POM_DESCRIPTION
pom.packaging POM_PACKAGING
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
configurations.implementation.allDependencies.each {
println "dependency=$it"
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
}
in the gradle.properties file:
POM_NAME=PackageName
POM_PACKAGING=aar
GROUP=com.companyname
POM_DESCRIPTION=CompanyName SDK Core library
VARIANT_SUFFIX is set from an env variable.
archivesBaseName is set in the module's build.gradle
Could you try lower casing your artifact ID?
I was facing the same issue and lowercasing it made it work.
Reference: https://github.community/t/gradle-maven-deploy-failing-with-422-unprocessable-entity/137299/3
In my case when the artifact had the name api or service or serde it was being blocked. eg. this worked <artifactId>database-ervice</artifactId> this did not database-service
Edit:
When using Postman to do the put request I got
Package "io.XXX.mydomain.xyz-service" is already associated with another repository. so realised that the package was previously deplloyed in another repo.
The maven-deployer-plugin is extremely poor at reporting the error message of the PUT response so had to use mintm to lookup the url and Postman to figure out the message.
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?
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 ?
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.
I have an Android-Library that I would like to publish on bintray.
So far so good, I am using the gradle-bintray-plugin 1.2 with the following configuration:
bintray {
user = properties.getProperty("bintray.user")
key = properties.getProperty("bintray.apikey")
configurations = ['archives']
pkg {
repo = "android" // thats how my maven repository is called on bintray
name = "mylibrary"
websiteUrl = "https://somewebsite" // replaced this, since the project should not matter
issueTrackerUrl = 'some issuetracker url'
vcsUrl = "some repository"
licenses = ["Apache-2.0"]
publish = true
version {
// the 2 functions here, are building the version number
name = versionNameBuild() // i.e. 1.0.0-SomeName
vcsTag = versionName() // 1.0.0
gpg {
// keys are uploaded
sign = true
}
}
}
}
The first issue I ran into, was that after I uploaded the library the Version number was "unspecified". Meaning, that the file was uploaded successfully, but it was called smth. like "mylibrary-unspecified.aar". I figured out that I had to additionally specify the project version number in gradle.
like this:
project.version = "1.0.1"
After that, this was working fine. Now I have only 2 Questions left:
I would expect my files to be uploaded like this:
$BINTRAYUSERNAME/$REPONAME/$PACKAGENAME/$VERSION/*.aar
But they are actually uploaded to smth like this:
$BINTRAYUSERNAME/$REPONAME/$PROJECT_FOLDERNAME_OF_ANDROID_STUDIO/$SUBDIRECTORY_OF_THE_LIBRARY/$VERSION/*.aar
Can I change this "path" somehow? Does it matter?
Which leads me to my next question.
How can I specify the maven group-type? I mean it's a maven repository right? So I should be able to set this up? Is this may be related to my first question?
Can I change this "path" somehow? Does it matter?
Yes and yes. This path changed, as soon as I used the group variable:
group = "my.awesome.group"
This solves the second Question as well. The path of the uploaded file is then:
$BINTRAYUSERNAME/$REPONAME/$PACKAGENAME/$GROUPPATH/$VERSION/*.aar
I recommend using for Android libraries the example script.