Gradle 'publishToMavenLocal' task not found. Please add the 'maven-publish' or 'maven' plugin
Asked Answered
F

1

7

I got an error when I deployed my library on jitpack eoor are below. and I have use Project full error is here --->

Build starting... Start: Fri May 27 13:31:41 UTC 2022 67cf7f81daef Git: edb3881 commit edb38816aca77f5b11d1a2be6fbe604d3e1e088c Author: Laxmi kant Date: Fri May 27 19:00:52 2022 +0530

this is my commit:--> added all

    Init SDKMan
    Found Android manifest
    Android SDK version: . Build tools: 
    Found gradle
    Gradle build script
    Found gradle version: 7.0.2.
    Using gradle wrapper
    Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
    Downloading https://services.gradle.org/distributions/gradle-7.0.2-bin.zip
   .10%.20%.30%.40%.50%.60%.70%.80%.90%.100%

   ------------------------------------------------------------
   Gradle 7.0.2
    ------------------------------------------------------------

   Build time:   2021-05-14 12:02:31 UTC
   Revision:     1ef1b260d39daacbf9357f9d8594a8a743e2152e

   Kotlin:       1.4.31
   Groovy:       3.0.7
   Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
    JVM:          1.8.0_292 (Private Build 25.292-b10)
   OS:           Linux 4.14.63-xxxx-std-ipv6-64 amd64

   0m3.269s
   Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
   openjdk version "1.8.0_292"
   OpenJDK Runtime Environment (build 1.8.0_292-8u292-b10-0ubuntu1~16.04.1-b10)
   OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)
   Getting tasks: ./gradlew tasks --all
   WARNING:  > Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
   Please specify Java version in jitpack.yml
   Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
   JVM:          11.0.2 (Oracle Corporation 11.0.2+9)
   Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
   Tasks: 

  ⚠️   WARNING:
   Gradle 'publishToMavenLocal' task not found. Please add the 'maven-publish' or 'maven' plugin.
   See the documentation and examples: https://docs.jitpack.io

   Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
   Running: ./gradlew clean -Pgroup=com.github.codewith-fun -Pversion=edb38816ac -xtest -xlint 
   publishToMavenLocal

   Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
   Use '--warning-mode all' to show the individual deprecation warnings.
   See 
   https://docs.gradle.org/7.0.2/userguide/command_line_interface.html#sec:command_line_warnings
   Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2

   FAILURE: Build failed with an exception.

   * Where:
   Build file '/home/jitpack/build/app/build.gradle' line: 2

   * What went wrong:
   An exception occurred applying plugin request [id: 'com.android.application']
   > Failed to apply plugin 'com.android.internal.application'.
   > Your project contains 2 or more modules with the same identification com.github.codewith- 
  fun:investwell
     at ":" and ":investwell".
     You must use different identification (either name or group) for each modules.

  * Try:
   Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get 
   more log output. Run with --scan to get full insights.

   * Get more help at https://help.gradle.org

   BUILD FAILED in 1s
   Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
   Build tool exit code: 0
   Looking for artifacts...
   Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
   Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8 -Dhttps.protocols=TLSv1.2
   Looking for pom.xml in build directory and ~/.m2
   2022-05-27T13:32:53.067115286Z
   Exit code: 0

   ⚠️ ERROR: No build artifacts found
Fracas answered 30/5, 2022 at 5:54 Comment(0)
P
13
  1. Open the project's build.gradle file.

  2. Add the reference to the Maven plugin: apply plugin: 'maven-publish'

  3. In the publishing section, specify the package properties (the generated package name will be groupId:artifactId). For example, we want to publish a .jar file (for the sake of length, the section content is reduced):

afterEvaluate {
    publishing {
        publications {
            release(MavenPublication) {
                from components.release
                groupId = 'com.github.mint'
                artifactId = 'mint-android-app'
                version = '0.0.4'
            }
        }
    }
}

Its Kotlin syntax would be:

    afterEvaluate {
        publishing {
            publications {
                create<MavenPublication>("maven") {
                    from (components["release"])
                    groupId = "com.github.mint"
                    artifactId = "mint-android-app"
                    version = "0.0.4"
                }
            }
        }
    }
Paramagnet answered 31/5, 2022 at 8:28 Comment(4)
How should this in gradle Kotlin syntax?Bullfrog
@LucasSousa plugins { `maven-publish` }Battleship
@Battleship When putting the plugins { maven-publish` } ` in the project kts file, it gives an error of Expression 'publishing' cannot be invoked as a function. The function 'invoke()' is not found, and when putting it in the library's module kts file, it works, but then jitpack still complains of Gradle 'publishToMavenLocal' task not found. Please add the 'maven-publish' or 'maven' plugin. See the documentation and examples: https://docs.jitpack.io . What should be done?Oolite
@androiddeveloper check the latest docs. It seems it is still the correct syntax docs.gradle.org/current/userguide/publishing_maven.htmlBattleship

© 2022 - 2024 — McMap. All rights reserved.