vanniktech / gradle-maven-publish-plugin

A Gradle plugin that publishes your Android and Kotlin libraries, including sources and javadoc, to Maven Central or any other Nexus instance.
https://vanniktech.github.io/gradle-maven-publish-plugin
Apache License 2.0
1.2k stars 110 forks source link

Credentials required for this build could not be resolved. #247

Closed a914-gowtham closed 3 years ago

a914-gowtham commented 3 years ago

I understand that I need to give credentials for sonatype account. but, I don't know where to give it. an example code be helpful

Error log

Credentials required for this build could not be resolved.
> The following Gradle properties are missing for 'mavenCentral' credentials:
    - mavenCentralUsername
    - mavenCentralPassword

library/gradle.properties

GROUP=io.a914-gowtham
POM_ARTIFACT_ID=compose-ratingbar
VERSION_NAME=1.0.2

POM_NAME=compose-ratingbar
POM_PACKAGING=aar

POM_DESCRIPTION=A Ratingbar for Jetpack Compose.
POM_INCEPTION_YEAR=2021

POM_URL=https://github.com/a914-gowtham/compose-ratingbar
POM_SCM_URL=https://github.com/a914-gowtham/compose-ratingbar
POM_SCM_CONNECTION=scm:git@github.com/a914-gowtham/compose-ratingbar.git
POM_SCM_DEV_CONNECTION=scm:git@github.com/a914-gowtham/compose-ratingbar.git

POM_LICENCE_NAME=The Apache Software License, Version 2.0
POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
POM_LICENCE_DIST=repo

POM_DEVELOPER_ID=gowtham27
POM_DEVELOPER_NAME=Gowtham
POM_DEVELOPER_URL=https://github.com/a914-gowtham

build.gradle(project)

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext {
        compose_version = '1.0.0-beta05'
        kotlin_version = "1.4.32"
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.0.0-alpha14'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlin_version}"
        classpath 'com.vanniktech:gradle-maven-publish-plugin:0.15.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

build.gradle(library)

plugins {
    id 'com.android.library'
    id 'kotlin-android'
    id 'com.vanniktech.maven.publish'
}

allprojects {
    plugins.withId("com.vanniktech.maven.publish") {
        mavenPublish {
            sonatypeHost = "S01"
        }
    }
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        consumerProguardFiles "consumer-rules.pro"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_11.toString()
        useIR = true
    }
    buildFeatures {
        buildConfig false
        compose true
    }
    composeOptions {
        kotlinCompilerExtensionVersion compose_version
        kotlinCompilerVersion kotlin_version
    }
}

dependencies {
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation "androidx.compose.foundation:foundation:$compose_version"
    implementation "androidx.compose.ui:ui:$compose_version"
    implementation "androidx.compose.material:material:$compose_version"
    implementation "androidx.compose.ui:ui-tooling:$compose_version"
}
victorpaleologue commented 3 years ago

Your Gradle code seems correct. However it seems you did not provide your maven credentials correctly. In the README (https://github.com/vanniktech/gradle-maven-publish-plugin#where-to-upload-to), it is stated that you need to set the Gradle properties mavenCentralUsername and mavenCentralPassword to be set to be able to upload to Maven Central. It is recommended to set them in ~/.gradle/gradle.properties. If you do not have these credentials yet, check out how to ask SonaType to create a free repository for your OSS. You will need to prove you are the owner of gowtham.com. If you can't, checkout GitHub Packages and their offer of per-project Maven repositories.

a914-gowtham commented 3 years ago

@victorpaleologue There is no file named gradle.properties under gradle folder. should I create one? and I have some other data as well. where do i have to set them.

signing.keyId=myKeyId
signing.password=password
signing.secretKeyRingFile=gpg-keys/myKeyId.gpg
mavenCentralUsername=Gowtham24
mavenCentralPassword=myPassword
victorpaleologue commented 3 years ago

Yes, precisely in ~/.gradle/gradle.properties. ~ stands for your home folder, and not the root of your project. So do not confuse it with the gradle folder of your project.

Also, beware of not sharing your keyring password here!

a914-gowtham commented 3 years ago

Thanks a lot that helped to solve. but I got another error. Is this same as yours issue which you created lastly

> Task :library:signMavenPublication FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':library:signMavenPublication'.
> Cannot perform signing task ':library:signMavenPublication' because it has no configured signatory