Gradle 7 and jitpack.io runs into error during publish
Asked Answered
L

6

18

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

Limburger answered 19/5, 2021 at 8:20 Comment(0)
L
28

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

Limburger answered 19/5, 2021 at 8:30 Comment(7)
Thanks. This worked. Have been search for 2 days on how to fix the Jitpack issueCompassion
Glad to help. I searched for days as well. Don't forget the question to up-vote ;-)Limburger
If I just copy the exact thing you posted and paste will it work?Anastaciaanastas
@MohammedAbidNafi Simply try it and after please rate itLimburger
Am sorry didnt work jitpack.io/com/github/MohammedAbidNafi/iOS-Style-Alert-Dialog/…Anastaciaanastas
@MohammedAbidNafi It works ! You simple have to fix other issues first github.com/MohammedAbidNafi/iOS-Style-Alert-Dialog/commit/…Limburger
@MohammedAbidNafi checkthis: github.com/MohammedAbidNafi/iOS-Style-Alert-Dialog/commit/…Dasheen
F
1

DSL version

    publishing {
      publications {
        val mavenJava by creating(MavenPublication::class) {
            from(components["java"])
        }
    }
}
Fyrd answered 23/7, 2021 at 18:35 Comment(0)
O
1

the answer from hannes ach worked for me.

With old gradle also a ...-sources.jar file was uploaded to jitpack. To restore that behavior, the gradle snippet has to be slightly enhanced:

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

task androidSourcesJar(type: Jar) {
    classifier 'sources'
    from android.sourceSets.main.java.srcDirs 
}
Ostracize answered 21/9, 2021 at 19:19 Comment(2)
Are you sure ? I did a test drive jitpack.io/com/github/hannesa2/virocoreCommunity/rc-1.20.2 and with sources jitpack.io/com/github/hannesa2/virocoreCommunity/… but content is the sameLimburger
works here: jitpack.io/com/github/mik3y/usb-serial-for-android/v3.4.3 + github.com/mik3y/usb-serial-for-android/blob/master/…Ostracize
V
1

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
            }
        }
    }
}
Vibrate answered 22/1, 2022 at 10:6 Comment(0)
G
1

The following worked for me in Groovy

group = [groupId]
version = [version]

task javadoc(type: Javadoc) {
    configurations.implementation.canBeResolved(true)
    configurations.api.canBeResolved(true)

    failOnError false

    source = android.sourceSets.main.java.srcDirs
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
    //destinationDir = file("../javadoc/")
    classpath += configurations.api
}

task sourcesJar(type: Jar) {
    from android.sourceSets.main.java.srcDirs
    archiveClassifier = "sources"
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from javadoc.destinationDir
}

artifacts {
    archives sourcesJar
    archives javadocJar
}

// Because the components are created only during the afterEvaluate phase, you must
// configure your publications using the afterEvaluate() lifecycle method.
afterEvaluate {
    publishing {
        publications {
            // Creates a Maven publication called "release".
            release(MavenPublication) {
                // Applies the component for the release build variant.
                from components.release
                artifact(sourcesJar)

                // You can then customize attributes of the publication as shown below.
                groupId = 'com.github.[name].[repo]'
                artifactId = '[submodule name]'
                version = '[version]'

                pom.withXml {
                    def dependenciesNode = (asNode().get("dependencies") as groovy.util.NodeList).get(0) as groovy.util.Node
                    def configurationNames = ["implementation", "api"]

                    configurationNames.forEach { configurationName ->
                        configurations[configurationName].allDependencies.forEach {
                            if (it.group != null && it.version != "unspecified") {
                                def dependencyNode = dependenciesNode.appendNode("dependency")
                                dependencyNode.appendNode("groupId", it.group)
                                dependencyNode.appendNode("artifactId", it.name)
                                dependencyNode.appendNode("version", it.version)
                                // dependencyNode.appendNode("scope", configurationName)
                            }
                        }
                    }
                }
            }
        }
    }
}

And the following worked for me in KTS

group = [groupId]
version = [version]

val sourcesJar by tasks.registering(Jar::class) {
    from(android.sourceSets["main"].java.srcDirs)
    archiveClassifier.set("sources")
}

val javadoc by tasks.registering(Javadoc::class) {
    configurations.implementation.get().isCanBeResolved = true
    configurations.api.get().isCanBeResolved = true

    isFailOnError = false
    source = android.sourceSets["main"].java.getSourceFiles()
    classpath += project.files(android.bootClasspath.joinToString(separator = File.pathSeparator))
    classpath += configurations.api
}

// build a jar with javadoc
val javadocJar by tasks.registering(Jar::class) {
    dependsOn(javadoc)
    archiveClassifier.set("javadoc")
    from(javadoc.get().destinationDir)
}

artifacts {
    archives(sourcesJar)
    archives(javadocJar)
}

afterEvaluate {
    publishing {
        publications {
            register("mavenJava", MavenPublication::class) {
                groupId = "com.github.[name].[repo]"
                artifactId = "[submodule name]"
                version = "[version]"

                from(components["release"])
                artifact(sourcesJar.get())

                pom.withXml {
                    val dependenciesNode: groovy.util.Node =
                        (asNode().get("dependencies") as groovy.util.NodeList).get(0) as groovy.util.Node
                    val configurationNames = arrayOf("implementation", "api")

                    configurationNames.forEach { configurationName ->
                        configurations[configurationName].allDependencies.forEach {
                            if (it.group != null && it.version != "unspecified") {
                                val dependencyNode = dependenciesNode.appendNode("dependency")
                                dependencyNode.appendNode("groupId", it.group)
                                dependencyNode.appendNode("artifactId", it.name)
                                dependencyNode.appendNode("version", it.version)
                                // dependencyNode.appendNode("scope", configurationName)
                            }
                        }
                    }
                }
            }
        }
    }
}

Beware that even with the withXML block, the transitive dependencies of api dependencies don't get added automatically. I had to add them manually.

Grume answered 21/4, 2022 at 17:25 Comment(0)
W
0

This is a known and documented issue:

  • Could not create plugin of type 'AndroidMavenPlugin'
  • Could not generate a decorated class for type AndroidMavenPlugin.
  • org/gradle/api/publication/maven/internal/MavenPomMetaInfoProvider

For my case I had to declare:

app/module/build.gradle

afterEvaluate {
    publishing {
        publications {
            release(MavenPublication) {
                from components.release
                groupId = 'com.github.alkathirikhalid'
                artifactId = 'connection'
                version = 'v1.0.9'
            }
        }
    }
}

and project/build.gradle

plugins {
    id 'maven-publish'
}

Reference:

Winifredwinikka answered 20/11, 2021 at 4:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.