maven-publish プラグインの使用に関する注意事項

-始める-

1. プラグインの紹介
maven-publish は、ローカル ライブラリを Apache Maven ウェアハウスに公開するために使用される Gradle プラグインです。例: *.aar、*.jar、およびその他のライブラリをウェアハウスに公開すると、gradle または maven を介してリモート依存関係として使用できます。

2. プラグインの導入
使用するモジュールの build.gradle ファイルに以下のコードを追加します。

apply plugin: 'maven-publish'

3. プラグインの使用 プラグ
インを導入した後、カスタム属性とタスクの一部を拡張できます。プラグインを導入するモジュールでは、発行ノードをオーバーライドすることでカスタム操作を実行できます。

pulishing の内部では、パブリケーションとリポジトリの 2 つの構成をオーバーライドできます。
具体的な構成については、Gradle 公式 Web サイトの紹介を参照してください。

publishing {
    //基本信息配置
    publications {
        maven(MavenPublication) {
            //配置组织结构信息(这里就是配置我们依赖时,所用到的libs结构信息 implementation 'com.xxx.androidlibs:xxx:1.0.0')
            groupId = 'com.xxx.androidlibs'
            artifactId = 'xxx'
            version = '1.0.0'

            //定义输出资源源文件位置
            artifact androidSourcesJar
            artifact("$buildDir/outputs/aar/xxx.aar")

            pom {
                //libs名称
                name = 'xxx'
                //libs官网(一般为GitHub libs 地址)
                url = 'http://www.example.com/library'
                //libs描述(功能介绍)
                description = 'xxx.'

                //开源协议
                licenses {
                    license {
                        name = 'The Apache License, Version 2.0'
                        url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                    }
                }

                //libs发布者信息
                developers {
                    developer {
                        id = 'xxx'
                        name = 'xxx'
                        email = '[email protected]'
                    }
                }

                //libs源码仓库信息
                scm {
                    connection = 'scm:git:git://example.com/my-library.git'
                    developerConnection = 'scm:git:ssh://example.com/my-library.git'
                    url = 'http://example.com/my-library'
                }
            }
        }
    }

    //maven仓库配置
    repositories {
        mavenLocal()//本地仓库(默认)
        maven {
            //本地maven地址配置(自定义,也可以是一个maven仓库地址)
            url = uri("${rootProject.projectDir}/repo")
        }
    }
}
task androidSourcesJar(type: Jar) {
    archiveClassifier = 'sources'
    from android.sourceSets.main.java.srcDirs
}

artifacts {
    archives androidSourcesJar
}

4. コンパイルコマンドコンパイルコマンドを実行すると、成功すると
信頼できるライブラリ
(com.xxx.androidlibs:xxx:1.0.0'実装)が生成されます
もちろんbuild.gradleでmavenの設定が必要ですプロジェクトのルート ディレクトリ Warehouse、つまりリポジトリ {} によって構成された情報。

./gradlew build publish

5. 注意が必要な事項:
artifact("$buildDir/outputs/aar/xxx.aar") はここにこの行を追加し、libs の build.gradle をdependency{ api files('libs/libddshare.jar')
の下に置きます。) } API を使用するには、依存するサードパーティ ライブラリが *.aar にまとめてパッケージ化されます。



6、完全なコード

ここでは、リソースを "$buildDir/outputs/aar/xxx.aar" buildDir にパッケージ化しているため、実行順序を保証するために afterEvaluate ノード パッケージが使用されています。

apply plugin: 'maven-publish'

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

artifacts {
    archives androidSourcesJar
}

afterEvaluate {
    publishing {
        //基本信息配置
        publications {
            maven(MavenPublication) {
                //配置组织结构信息(这里就是配置我们依赖时,所用到的libs结构信息 implementation 'com.xxx.androidlibs:xxx:1.0.0')
                groupId = 'com.xxx.androidlibs'
                artifactId = 'xxx'
                version = '1.0.0'

                //定义输出资源源文件位置
                artifact androidSourcesJar
                artifact("$buildDir/outputs/aar/xxx.aar")

                pom {
                    //libs名称
                    name = 'xxx'
                    //libs官网(一般为GitHub libs 地址)
                    url = 'http://www.example.com/library'
                    //libs描述(功能介绍)
                    description = 'xxx.'

                    //开源协议
                    licenses {
                        license {
                            name = 'The Apache License, Version 2.0'
                            url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                        }
                    }

                    //libs发布者信息
                    developers {
                        developer {
                            id = 'xxx'
                            name = 'xxx'
                            email = '[email protected]'
                        }
                    }

                    //libs源码仓库信息
                    scm {
                        connection = 'scm:git:git://example.com/my-library.git'
                        developerConnection = 'scm:git:ssh://example.com/my-library.git'
                        url = 'http://example.com/my-library'
                    }
                }
            }
        }

        //maven仓库配置
        repositories {
            mavenLocal()//本地仓库(默认)
            maven {
                //本地maven地址配置(自定义,也可以是一个maven仓库地址)
                url = uri("${rootProject.projectDir}/repo")
            }
        }
    }
}

-終わり-

おすすめ

転載: blog.csdn.net/github_35033182/article/details/120064146