Search code examples
androidmavengradlepublishjitpack

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

  • 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