10

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 :)

galusben
  • 5,948
  • 6
  • 33
  • 52
Deven
  • 3,078
  • 1
  • 32
  • 34

2 Answers2

16

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'
        }
    }
}
galusben
  • 5,948
  • 6
  • 33
  • 52
  • When i use username instead of organization i'm getting the error :- Could not create package 'devsideal/maven/acr': HTTP/1.1 404 Not Found [message:Repo 'maven' was not found] .... ? – Deven Oct 11 '16 at 06:13
  • You shall use your username for authentication. But use your organisation name for the repository path. Here: https://github.com/bintray/gradle-bintray-plugin#step-3-add-the-bintray-configuration-closure-to-your-buildgradle-file You use your username. In the repo path put your org name. – galusben Oct 11 '16 at 07:48
  • can you share your build.gradle file? – galusben Oct 11 '16 at 07:58
  • I missed userOrg, Now it's solved by adding just userOrg = 'myorgname' in bintray, Thanks. – Deven Oct 12 '16 at 07:05
  • Hi @gba i have successfully uploaded my first library on jcenter, thanks for your help :) I was need of some updates in library so i deleted all files from bintray and again build and uploaded successfully my updated library with same version on bintray, but when i sync its still showing old, Its take some time to update ? How many time ? OR I can't update library with old version ? I will need to update library version as well ? – Deven Oct 13 '16 at 05:56
  • Congrats for uploading to Bintray updates shall be almost immediate, meaning upload is immediate, but publishing can take some time (seconds to minutes). I suggest you to contact JFrog support, since it seems like your problem is too specific for here... – galusben Oct 13 '16 at 15:42
  • Okay, Thanks gba. – Deven Oct 14 '16 at 05:38
  • @Deven can you upload example on github? I still received 401 or 404 error :( – Sergey Molyak Nov 11 '16 at 07:22
  • You save my day – wanz Aug 03 '18 at 18:35
1

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/

Ashu
  • 2,970
  • 1
  • 19
  • 31