Giter Site home page Giter Site logo

gradle-maven-plugin's Introduction

Gradle Maven Plugin

This is a small "plugin" to simplify the use of maven-publish Gradle plugin. You can use this plugin for Java Library and Android Library.

Index

In order to use GradleMavenizer you have to add the line

apply from: 'https://raw.githubusercontent.com/sky-uk/gradle-maven-plugin/master/gradle-mavenizer.gradle'

at the very bottom of the build.gradle file. Alternatively, to use a specific release version, add this property to the project (see Releases at the top of the Github page for released versions):

mavPluginVersion = '1.2.0'

and add this line to the very bottom of the build.gradle file:

apply from: "https://raw.githubusercontent.com/sky-uk/gradle-maven-plugin/${project.mavPluginVersion}/gradle-mavenizer.gradle"`

GradleMavenizer is highly customizable.

You can customize it adding some properties to the root project build.gradle or to the module build.gradle file.

Attention: If you add the same property to the root project file and to the module file, in order of priority, the module file property will override the root project property.

  • mavProjectName -> String property -> Identify the project name (can be different from the artifactId)
  • mavLibraryDescription -> String property -> A simple description for the library
  • mavDevelopers -> Map property -> A map with the ids and the developer name of the library
  • mavLibraryLicenses -> Map property -> A map with the name and the urls of the library licenses
  • mavSiteUrl -> String property -> Identify the url of the project website
  • mavGitUrl -> String property ->Identify the url of the project github page
  • Remote repository:

    • mavPublishToRemoteRepo -> Boolean property -> Allow the script to load your library to a remote repo
    • mavRemoteRepoUser -> String property -> Username to grant access to the remote repo
    • mavRemoteRepoPassword -> String property -> Password to grant access to the remote repo
    • mavRepoRemoteUrl -> String property -> Identify the url of the remote repo
  • Internal repository:

    • mavPublishToInternalRepo -> Boolean property -> Allow the script to load your library to an internal repo
    • mavRepoInternalUrl -> String property -> Identify the url of the internal repo
  • MavenLocal repository:

    • mavPublishToMavenLocal -> Boolean property -> Allow the script to load your library to MavenLocal folder

Attention: If you won't set any repository automatically the script will use MavenLocal as default repo

project.ext {
    mavDevelopers = ["Fe":"Federico"]
    mavSiteUrl = "https://github.com/sky-uk/gradle-maven-plugin"
    mavGitUrl = mavSiteUrl + '.git'
    mavProjectName = 'GradleMavenizer'
    mavPublishToInternalRepo = true
    mavRepoInternalUrl = "path/to/internal/repo"
    mavLibraryLicenses = ["Apache-2.0":'http://www.apache.org/licenses/LICENSE-2.0.txt']
    mavLibraryDescription = "A simple description of the project"
}

To finally publish you library you can use the command ./gradlew publish directly from your project root folder.

You can also pass some properties directly from command line using the command -P (every property must have -P before), for example: ./gradlew publish -PmavPublishToMavenLocal=true

Follow this guide if you need to get a Sonatype account and generate a GPG key. Those matters are out of scope here.

In your project root, add local.properties (make sure to ignore it in your repo and not commit it) with the following content:

signing.keyId=ABCDEFGH
signing.password=yourPassword
signing.secretKeyRingFile=/path/to/ABCDEFGH.gpg

mavRepoRemoteUrl=https://oss.sonatype.org/service/local/staging/deploy/maven2/
mavRemoteRepoUser=yourSonatypeUsername
mavRemoteRepoPassword=yourSonatypePassword

Then to publish a staging repository on Maven Central execute:

./gradlew publish -PmavSigning=true -PmavPublishToRemoteRepo=true --max-workers 1

The --max-workers 1 setting is important to ensure the publication does not get split in multiple publications when using gradle parallel builds, resulting in many stagng repositories on sonatype. It's always advised to specify it.

After you executed the command, you can browse and review what's been uploaded by visiting https://oss.sonatype.org/#stagingRepositories

If you want to generate the POM file without publish your library you can use the command ./gradlew generatePomFileForMavenPublishPublication directly from your project root folder.

To generate the POM file only for one module of your library you can use the command ./gradlew your-module-name:generatePomFileForMavenPublishPublication where you have to replace your-module-name with the name you chose for your module.

Note: POM file will be saved in build/publications/mavenPublish/ as pom-default.xml

gradle-maven-plugin's People

Contributors

aleksaboskov avatar cypherdare avatar gotev avatar jokermonn avatar sdiawara avatar skyfaccincania avatar skymontif avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gradle-maven-plugin's Issues

Publish the third aar dependencies

In my library module. I add a dependence as it says:

allprojects {
    repositories {
        jcenter()
        mavenCentral()
        maven { url "https://dl.bintray.com/thelasterstar/maven/" }
    }
}
compile 'com.sina.weibo.sdk:core:4.3.8:openDefaultRelease@aar'

NOTICE: The coordinate with openDefaultRelease part.

Also I try the other method:

repositories{
    flatDir {
        dirs 'libs'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:24.2.1'
    compile(name: 'openDefault-4.3.9', ext: 'aar')

}

But when I run ./gradlew publish the both don't containe the dependence.

Upload to Bintray?

I want to upload to Bintray, can this plugin do that? I see the mavRemoteRepo is that what I need to use? If so do I give it the username and password to my bintray account? And what Url do I pass?

Have full Doc ?

Dear Sir

Sorry for my poor English & knowledge

Do you can create a full Android Demo Project ?

THX

`mavVersion` not work

  • I create a project with a library by Android Studio 3.4.1. The library build file relative configs below:
project.ext {
    mavDevelopers = ["Sugerlad":"苏格拉弟"]
    mavSiteUrl = "https://github.com/sugarlad/BiliShare"
    mavGitUrl = mavSiteUrl + '.git'
    mavProjectName = 'BiliShare'
    mavPublishToInternalRepo = true
    mavRepoInternalUrl = "/Users/DDD/Documents/jitpack"
    mavLibraryLicenses = ["Apache-2.0":'http://www.apache.org/licenses/LICENSE-2.0.txt']
    mavLibraryDescription = "Support for sharing to Weibo, QQ Chat, QQ Zone, Wechat Chat and Wechat Moment etc.. 支持分享到微博、QQ聊天、QQ空间、微信聊天、微信朋友圈,系统分享等"
    mavVersion = "0.1.1"
}

apply from: 'https://raw.githubusercontent.com/sky-uk/gradle-maven-plugin/master/gradle-mavenizer.gradle'
  • I run command in Terminal on the root folder ./gradlew publish or ./gradlew publish -PmavVersion="0.1.1". I find the local repo has not version info.
<project xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>BiliShare</groupId>
  <artifactId>library</artifactId>
  <version>unspecified</version>
  <packaging>aar</packaging>
  <name>BiliShare</name>
  <description>Support for sharing to Weibo, QQ Chat, QQ Zone, Wechat Chat and Wechat Moment etc.. 支持分享到微博、QQ聊天、QQ空间、微信聊天、微信朋友圈,系统分享等</description>
  <url>https://github.com/sugarlad/BiliShare</url>
  <licenses>
    <license>
      <name>Apache-2.0</name>
      <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
    </license>
  </licenses>
  <developers>
    <developer>
      <id>Sugerlad</id>
      <name>苏格拉弟</name>
    </developer>
  </developers>
  <scm>
    <connection>https://github.com/sugarlad/BiliShare.git</connection>
    <developerConnection>https://github.com/sugarlad/BiliShare.git</developerConnection>
    <url>https://github.com/sugarlad/BiliShare</url>
  </scm>
</project>
  • Some other infos for you:
------------------------------------------------------------
Gradle 5.1.1
------------------------------------------------------------

Build time:   2019-01-10 23:05:02 UTC
Revision:     3c9abb645fb83932c44e8610642393ad62116807

Kotlin DSL:   1.1.1
Kotlin:       1.3.11
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM:          1.8.0_45 (Oracle Corporation 25.45-b02)
OS:           Mac OS X 10.13.4 x86_64

unable to resolve project version for andorid library

image

see this commit: https://github.com/hereisderek/android-util/tree/dc3455a

module build.gradle file:

apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'maven-publish'


android {
    compileSdkVersion 29
    buildToolsVersion "29.0.1"



    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 29
        versionCode 2
        versionName "0.1.6"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        consumerProguardFiles 'consumer-rules.pro'
    }

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

    kotlinOptions {
        freeCompilerArgs = ["-XXLanguage:+InlineClasses"]
    }

    compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }


}


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'com.jakewharton.timber:timber:4.7.1'
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.core:core-ktx:1.0.2'

    implementation 'androidx.viewpager2:viewpager2:1.0.0-beta03'

    implementation ("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.2")
    implementation ("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.2.2")
    implementation ("org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.11.2-1.3.50-eap-5")


    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

project.ext {
    mavSiteUrl = "https://github.com/hereisderek/android-util"
    mavGitUrl = mavSiteUrl + '.git'
    mavProjectName = 'android-util'
    mavPublishToMavenLocal = true
    mavLibraryLicenses = ["Apache-2.0":'http://www.apache.org/licenses/LICENSE-2.0.txt']
    mavLibraryDescription = "A collection of android utilies"
}

apply from: 'https://raw.githubusercontent.com/sky-uk/gradle-maven-plugin/master/gradle-mavenizer.gradle'

Note to users migrating from dcendents/android-maven-gradle-plugin

Problem

I migrated my project from dcendents/android-maven-gradle-plugin (deprecated) in order to publish my libraries to local maven (~/.m2 directory). This worked fine after following the instructions. I could refer these libraries in my app and everything seemed to work fine. But found an issue with one of my apps that use .so files from these libraries. When I built this app, the apk file didn't have .so files from my library (from maven local).

Troubleshooting

The old plugin was populating entries in maven-metadata-local.xml while the new plugin (this project) uses a different xml, maven-metadata.xml. For some reason, the presence of maven-metadata-local.xml prevented gradle from packaging those .so files.

Solution

In my case, I just cleared ~/.m2 directory and published my libraries (using plugin from this project). Now if I refer these libraries in my app project, I see that the apk has the .so files from the published libraries.

Alternatively, deleting or updating maven-metadata-local.xml under ~/.m2 also solves this problem.


Just wanted to share this info so that you don't have to waste a day like I did :--).

I don't know if this project needs to do anything to prevent this problem. So I will just close this issue.

Is there a way to publish debug variant?

I use this plugin to publish my library to local maven. ./gradlew publish builds release variant and publishes it. At times, I would like to have debug variant published instead of release. This is useful for debugging purchase (particularly C++).

I couldn't find a way gradle-maven-plugin provides to choose the variant to publish. If there is a way, please let me know. If not, please consider adding an option to choose the variant to publish.

pom.xml

How do I generate a pom.xml?

Unknown tag when trying to publish

  • Env
------------------------------------------------------------
Gradle 5.1.1
------------------------------------------------------------

Build time:   2019-01-10 23:05:02 UTC
Revision:     3c9abb645fb83932c44e8610642393ad62116807

Kotlin DSL:   1.1.1
Kotlin:       1.3.11
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM:          1.8.0_45 (Oracle Corporation 25.45-b02)
OS:           Mac OS X 10.13.4 x86_64

  • Des
    Project with a library by Android Studio 3.4.1. The library build file relative configs below:
project.ext {
    mavDevelopers = ["X":"Sugerlad"]
    mavSiteUrl = "https://github.com/sugarlad/BiliShare"
    mavGitUrl = mavSiteUrl + '.git'
    mavProjectName = 'BiliShare'
    mavPublishToInternalRepo = true
    mavRepoInternalUrl = "/Users/DDD/Documents/jitpack"
    mavLibraryLicenses = ["Apache-2.0":'http://www.apache.org/licenses/LICENSE-2.0.txt']
    mavLibraryDescription = "Support for sharing to Weibo, QQ Chat, QQ Zone, Wechat Chat and Wechat Moment etc.. 支持分享到微博、QQ聊天、QQ空间、微信聊天、微信朋友圈,系统分享等"
    mavVersion = "0.1.1"
}

apply from: 'https://raw.githubusercontent.com/sky-uk/gradle-maven-plugin/master/gradle-mavenizer.gradle'
  • Publish
    run ./gradlew publish on root directory

  • Problem

Error: unknown tag: email
 * @email [email protected]

Add the option to skip JavaDoc creation?

Hi Guys,
thanks for the plugin. I think it would be worth to add the option to skip the Javadoc creation if you don't want to push it to a repo.
I guess it would be as simple as:

in gradle-mavenizer.gradle:

def publishJavaDoc= getBooleanProperty("mavPublishJavaDoc")

    publications {
        mavenPublish(MavenPublication) {
            if (isAndroidProject()) {
                artifact bundleReleaseAar
                if (publishJavaDoc){
                   artifact androidJavadocsJar
                 }                    
                artifact androidSourcesJar
            } else {
                artifact jar
                artifact sourcesJar                    
                if (publishJavaDoc){
                   artifact javadocJar
                 } 
            }
            
            decoratePom(pom)
        }
    }

Received status code 405 from server: Method Not Allowed

Configuration:

project.ext {
    mavDevelopers = ["ME":"Developers"]
    mavSiteUrl = "https://aria2.kezaihui.com/ME/android_lib"
    mavGitUrl = "[email protected]:ME/android_lib.git"
    mavProjectName = 'ZaihuiLib'
    mavLibraryLicenses = ["Apache-2.0":'http://www.apache.org/licenses/LICENSE-2.0.txt']
    mavLibraryDescription = "Android lib for Zaihui App"
    mavPublishToRemoteRepo = true
    mavRemoteRepoUser = MAVEN_USER
    mavRemoteRepoPassword = MAVEN_PASSWORD
    mavRepoRemoteUrl = MAVEN_URL
}

MAVEN_URL is "https://dl.bintray.com/zaihuime/maven/", I got this error message. May be I should change the HTTP Method PUT to POST, but I don't know how I can do it. Any help? Thanks.


Task :lib-android:publishMavenPublishPublicationToMavenRepository FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':lib-android:publishMavenPublishPublicationToMavenRepository'.

Failed to publish publication 'mavenPublish' to repository 'maven'
Could not write to resource 'https://dl.bintray.com/zaihuime/maven/com/zaihui/lib-android/1.0.0/lib-android-1.0.0.aar'.
> Could not PUT 'https://dl.bintray.com/zaihuime/maven/com/zaihui/lib-android/1.0.0/lib-android-1.0.0.aar'. Received status code 405 from server: Method Not Allowed

  • 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.

Allow choosing version

It would be nice if you could set a string property to select a specific commit from this repository instead of the latest commit from master. These lines could use the string property if it exists but default to "master" if it doesn't.

I know this doesn't matter yet, but if there are future changes that cause behavior changes, I'd prefer to opt-in to new changes.

422 from server: Unprocessable Entity when trying to publish

Execution failed for task ':imagekit:publishMavenPublishPublicationToMavenRepository'.

Failed to publish publication 'mavenPublish' to repository 'maven'
Could not write to resource 'https://github.com/imagekit-developer/imagekit-android/ImageKit/imagekit/unspecified/imagekit-unspecified.aar'.
> Could not PUT 'https://github.com/imagekit-developer/imagekit-android/ImageKit/imagekit/unspecified/imagekit-unspecified.aar'. Received status code 422 from server: Unprocessable Entity

project.ext {
mavSiteUrl = "https://imagekit.io/"
mavGitUrl = "https://github.com/imagekit-developer/imagekit-android.git"
mavProjectName = 'ImageKit'
mavPublishToRemoteRepo = true
mavRemoteRepoUser = "rjain90"
mavRemoteRepoPassword = "mzoq0987"
mavRepoRemoteUrl = "https://github.com/imagekit-developer/imagekit-android.git"
mavLibraryLicenses = ["Apache-2.0":'http://www.apache.org/licenses/LICENSE-2.0.txt']
mavLibraryDescription = "ImageKit android SDK"
mavVersion = "1.0"
}

Don't reference "compile" when it's not present

In the latest Android Gradle Plugin Canary, compile has been removed in favor of implementation and api. That results in this line failing during build:

configurations.compile.getDependencies().each { dep -> addDependency(dep, "compile") }

Execution failed for task ':views:generatePomFileForMavenPublishPublication'.
> Could not apply withXml() to generated POM
   > Could not get unknown property 'compile' for configuration container of type org.gradle.api.internal.artifacts.configurations.DefaultConfigurationContainer.

I don't know much about Groovy syntax, but I think adding a check before accessing the property should quickly solve this problem.

Could not get unknown property 'bundleReleaseAar' for object

project.ext {
mavDevelopers = ["en":"Naval"]
mavSiteUrl = "giturl"
mavGitUrl = mavSiteUrl + '.git'
mavProjectName = 'Communication'
mavPublishToInternalRepo = true
mavRepoInternalUrl = "${System.env.HOME}/.m2/repository/"
mavLibraryLicenses = ["Apache-2.0":'http://www.apache.org/licenses/LICENSE-2.0.txt']
mavLibraryDescription = "This Libray help in communicating with the server"
mavPluginVersion = '1.0.3'
}

apply from: "https://raw.githubusercontent.com/sky-uk/gradle-maven-plugin/${project.mavPluginVersion}/gradle-mavenizer.gradle"

FAILURE: Build failed with an exception.

Could not get unknown property 'bundleReleaseAar' for object of type org.gradle.api.publish.maven.internal.publication.DefaultMavenPublication.

incompatible with github action android ci

error message:


2019-08-31T05:42:48.1460703Z > Configure project :base
2019-08-31T05:42:48.1463572Z File /home/runner/.android/repositories.cfg could not be loaded.
2019-08-31T05:42:48.5420721Z Checking the license for package Android SDK Build-Tools 29.0.1 in /usr/local/lib/android/sdk/licenses
2019-08-31T05:42:48.5422130Z License for package Android SDK Build-Tools 29.0.1 accepted.
2019-08-31T05:42:48.5422838Z Preparing "Install Android SDK Build-Tools 29.0.1 (revision: 29.0.1)".
2019-08-31T05:42:48.5423167Z Warning: Failed to read or create install properties file.
2019-08-31T05:42:48.6422835Z 
2019-08-31T05:42:48.6454723Z FAILURE: Build failed with an exception.
2019-08-31T05:42:48.6461484Z 
2019-08-31T05:42:48.6461954Z * Where:
2019-08-31T05:42:48.6462902Z Script 'https://raw.githubusercontent.com/sky-uk/gradle-maven-plugin/master/artifact-javadoc-handler.gradle' line: 9
2019-08-31T05:42:48.6464623Z 
2019-08-31T05:42:48.6466843Z * What went wrong:
2019-08-31T05:42:48.6467160Z A problem occurred evaluating script.
2019-08-31T05:42:48.6467477Z > Failed to install the following SDK components:
2019-08-31T05:42:48.6468084Z       build-tools;29.0.1 Android SDK Build-Tools 29.0.1
2019-08-31T05:42:48.6468446Z   The SDK directory is not writable (/usr/local/lib/android/sdk)
2019-08-31T05:42:48.6468736Z 
2019-08-31T05:42:48.6468942Z 

raw log can be found here

project here

How to set custom name for the artifact

How to set custom name attribute for the artifact:

1. Group
2. Name
3. Version

as mentioned in your example
dependencyNode.appendNode('groupId', dep.group)
dependencyNode.appendNode('artifactId', dep.name)
dependencyNode.appendNode('version', dep.version)

as above are not accessible in your case and also there is no global variable defined for this:

project.ext {
mavDevelopers = ["Fe":"Federico"]
mavSiteUrl = "https://github.com/sky-uk/gradle-maven-plugin"
mavGitUrl = mavSiteUrl + '.git'
mavProjectName = 'GradleMavenizer'
mavPublishToInternalRepo = true
mavRepoInternalUrl = "path/to/internal/repo"
mavLibraryLicenses = ["Apache-2.0":'http://www.apache.org/licenses/LICENSE-2.0.txt']
mavLibraryDescription = "A simple description of the project"
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.