美文网首页
maven-publish

maven-publish

作者: 肖散 | 来源:发表于2022-10-13 11:03 被阅读0次

    userguide

    针对javadoc中文乱码

    可以在环境变量中添加

     JAVA_TOOL_OPTIONS     
     -Dfile.encoding=UTF-8
    
    图例

    1. 基本用法

    执行完全部的操作后进行打包
    最后执行 publishMainPublicationToMavenRepository任务即可


    执行
    //***************************** 打包发布 *****************************************
    apply plugin: 'maven-publish'
    ///说明文档
    def DESCRIPTION = 'xxxxxxxxxxxxxxxxx '
    def VERSION = theVersionNameCode + '-beta1'
    //Executing tasks: [publishMainPublicationToMavenRepository] in project  
    afterEvaluate {
        publishing {
            repositories {
                maven {
                    url = "file://${file("../xxxxx/").absolutePath}"
                }
            }
            publications {
                Main(MavenPublication) {
                    // The following applies a component to this publication
                    // which results in publishing an app bundle.
                    from components.release
                    groupId = 'com.xxxx'
                    artifactId = 'xxxxx'
                    version = VERSION 
                    pom {
                        description = DESCRIPTION
                        properties = [
                                'git-Log'       : gitLog,
                                'git-branch'    : branch,
                                'git-CommitHash': gitCommitHash,
                                'build-time'    : time
                        ]
                    }
                }
            }
        }
    }
    

    2.额外操作,比如插入本地jar包到aar中

    通过查看任务的执行步骤,在程序最后打包发布之前,替换我们需要的东西即可。如下中插入了myCopy任务。将本地的jar包放到aar中

    afterEvaluate {
        writeReleaseAarMetadata.dependsOn(myCopy)
        publishing  { *****    }     
    }
    
    task zipAssets(type: Zip) {
        from('./assets/')
        baseName 'classes'
        extension 'jar'
        doLast {
            println("+++++++++zipAssets+++++++++"+file('./').absolutePath)
        }
    }
    
    task myCopy(type: Copy,dependsOn:['zipAssets']) {
        delete('build/intermediates/aar_main_jar/release/classes.jar')
        from 'build/distributions/classes.jar'
        into 'build/intermediates/aar_main_jar/release/'
        doLast {
            println("+++++++++myCopy+++++++++"+file('./').absolutePath)
        }
    }
    
    > Task :midashisdk:preBuild UP-TO-DATE
    > Task :midashisdk:preReleaseBuild UP-TO-DATE
    > Task :midashisdk:compileReleaseAidl NO-SOURCE
    > Task :midashisdk:mergeReleaseJniLibFolders
    > Task :midashisdk:mergeReleaseNativeLibs NO-SOURCE
    > Task :midashisdk:stripReleaseDebugSymbols NO-SOURCE
    > Task :midashisdk:compileReleaseRenderscript NO-SOURCE
    > Task :midashisdk:copyReleaseJniLibsProjectAndLocalJars
    > Task :midashisdk:generateReleaseBuildConfig
    > Task :midashisdk:generateReleaseResValues
    > Task :midashisdk:generateReleaseResources
    > Task :midashisdk:packageReleaseResources
    > Task :midashisdk:javaPreCompileRelease
    > Task :midashisdk:mergeReleaseShaders
    > Task :midashisdk:compileReleaseShaders NO-SOURCE
    > Task :midashisdk:generateReleaseAssets UP-TO-DATE
    > Task :midashisdk:packageReleaseAssets
    > Task :midashisdk:packageReleaseRenderscript NO-SOURCE
    > Task :midashisdk:prepareLintJarForPublish
    > Task :midashisdk:prepareReleaseArtProfile
    > Task :midashisdk:processReleaseJavaRes NO-SOURCE
    > Task :midashisdk:parseReleaseLocalResources
    
    > Task :midashisdk:zipAssets
    +++++++++zipAssets+++++++++J:\workdata\midashisdk-Android\midashisdk
    
    > Task :midashisdk:myCopy
    +++++++++myCopy+++++++++J:\workdata\midashisdk-Android\midashisdk
    
    > Task :midashisdk:writeReleaseAarMetadata
    > Task :midashisdk:processReleaseManifest
    > Task :midashisdk:generatePomFileForMainPublication
    > Task :midashisdk:mergeReleaseJavaResource
    > Task :midashisdk:generateReleaseRFile
    > Task :midashisdk:extractReleaseAnnotations
    > Task :midashisdk:compileReleaseJavaWithJavac
    > Task :midashisdk:mergeReleaseGeneratedProguardFiles
    > Task :midashisdk:mergeReleaseConsumerProguardFiles
    > Task :midashisdk:syncReleaseLibJars
    > Task :midashisdk:bundleReleaseAar
    > Task :midashisdk:generateMetadataFileForMainPublication
    > Task :midashisdk:publishMainPublicationToMavenRepository
    

    3. 本地既有aar发布

    已经有了aar,不用去跑程序。可以直接通过指定artifact 来实现

    apply plugin: 'maven-publish'
    configurations.maybeCreate("default")
    def publishArtifact = artifacts.add("default", file('libs/xxx.aar' ))
    
    publishing {
        repositories {
            maven {
                url = "file://${file("../maven/").absolutePath}"
            }
        }
        publications {
            aar(MavenPublication) {
                groupId = 'com.xxxx'
                artifactId = 'xxxx'
                version = xxxxx
                artifact publishArtifact
            }
        }
    }
    

    相关文章

      网友评论

          本文标题:maven-publish

          本文链接:https://www.haomeiwen.com/subject/iuhfzrtx.html