Gradle 7 and jitpack.io runs into error during publish

When I upgrade in an Android project to Gradle 7.0 and want to publish aar library in jitpack.io I run into

Script '/script/maven-plugin.gradle' line: 2

* What went wrong:
A problem occurred evaluating script.
> Failed to apply plugin 'com.github.dcendents.android-maven'.
   > Could not create plugin of type 'AndroidMavenPlugin'.
      > Could not generate a decorated class for type AndroidMavenPlugin.
         > org/gradle/api/publication/maven/internal/MavenPomMetaInfoProvider 

See full log https://jitpack.io/com/github/appdevnext/moka/0.7.1/build.log


Solution 1:

The maven plugin has been eliminated in Gradle 7.0, please use the maven-publish plugin instead.

I made it work with

plugins {
    id 'maven-publish'
    ...
}

task androidSourcesJar(type: Jar) {
    classifier 'sources'
    from android.sourceSets.main.java.srcDirs 
}

project.afterEvaluate {
    publishing {
        publications {
            release(MavenPublication) {
                from components.release
                artifact androidSourcesJar // optional sources
            }
        }
    }
}

and you need an own jitpack.yml

jdk:
  - openjdk11
install:
  - ./gradlew build :lib:publishToMavenLocal

Here you see complete pull request https://github.com/AppDevNext/Moka/pull/77 now it works https://jitpack.io/#AppDevNext/moka/1.0

Solution 2:

DSL version

    publishing {
      publications {
        val mavenJava by creating(MavenPublication::class) {
            from(components["java"])
        }
    }
}

Solution 3:

I did these 3 steps (Called jitpack, Define Java ver. ,Publish Maven) please follow them!

1- In build.gradle(Project:...) add:

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

then under buildscript part, add:

plugins {
    id 'maven-publish'
}

2- In build.gradle(Module:app), in android part add:

compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }

3- In build.gradle(Module:module-name), after dependencies part add:

afterEvaluate {
    publishing {
        publications {
            release(MavenPublication) {
                from components.release
                groupId = 'com.github.yourgitid' //your git id
                artifactId = 'Myket-Intent' //your-repository
                version = '0.1.15' // As same as the Tag
            }
        }
    }
}