Code Monkey home page Code Monkey logo

Comments (2)

msdx avatar msdx commented on July 2, 2024

我有用过一个脚本,用于发布到maven上的,你可以参考一下:

apply plugin: 'maven'
apply plugin: 'signing'
group = PROJ_GROUP
version = PROJ_VERSION
ext {
    UsingSonatype = hasProperty('UsingSonatype')
    isReleaseVersion = !version.endsWith("-SNAPSHOT")
// Defind in ~/.gradle/gradle.properties
    ReleaseUrl = UsingSonatype ? SONATYPE_RELEASE_URL : LOCAL_RELEASE_URL
    SnapshotUrl = UsingSonatype ? SONATYPE_SNAPSHOT_URL : LOCAL_SNAPSHOT_URL
    Username = UsingSonatype ? SONATYPE_USER : LOCAL_USERNAME
    Password = UsingSonatype ? SONATYPE_PASS : LOCAL_PASSWORD
    publishAar = hasProperty('aar') ? true : false
}
tasks.withType(JavaCompile) {
    options.encoding = "UTF-8"
}

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

task javadoc(type: Javadoc) {
    source = android.sourceSets.main.java.srcDirs
    classpath += configurations.compile
    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}

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

javadoc {
    options{
        encoding "UTF-8"
        charSet 'UTF-8'
        author true
        version true
        links "http://docs.oracle.com/javase/7/docs/api/"
        links "http://androiddoc.qiniudn.com/reference/"
        title PROJ_NAME
    }
}

artifacts {
    archives javadocJar
    archives sourcesJar
}
afterEvaluate { project ->
    artifacts {
        archives packageReleaseJar
    }
    signing {
        required { isReleaseVersion && gradle.taskGraph.hasTask("uploadArchives") }
        sign configurations.archives
    }

    uploadArchives {
        repositories {
            mavenDeployer {
                beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
                pom.groupId = PROJ_GROUP
                pom.artifactId = PROJ_ARTIFACT_ID
                pom.version = version
                repository(url: ReleaseUrl) {
                    authentication(userName: Username, password: Password)
                }
                snapshotRepository(url: SnapshotUrl) {
                    authentication(userName: Username, password: Password)
                }
                pom.project {
                    inceptionYear PROJ_INCEPTION_YEAR
                    name PROJ_NAME
                    packaging publishAar ? 'aar' : 'jar'
                    description PROJ_DESCRIPTION
                    url PROJ_URL
                    scm {
                        url SCM_URL
                        connection SCM_CONNECTION
                        developerConnection SCM_DEV_CONNECTION
                    }
                    licenses {
                        license {
                            name LICENSE_NAME
                            url LICENSE_URL
                            distribution LICENSE_DISTRIBUTION
                        }
                    }
                    developers {
                        developer {
                            id DEVELOPER_ID
                            name DEVELOPER_NAME
                        }
                    }
                }
            }
        }
    }
}

属性文件如下:

PROJ_GROUP=
PROJ_VERSION=
PROJ_NAME=
PROJ_DESCRIPTION=ARM  SDK
PROJ_ARTIFACT_ID=
PROJ_INCEPTION_YEAR=2015
PROJ_URL=

SCM_URL=
SCM_CONNECTION=
SCM_DEV_CONNECTION=

LICENSE_NAME=The Apache Software License, Version 2.0
LICENSE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
LICENSE_DISTRIBUTION=repo

DEVELOPER_ID=
DEVELOPER_NAME=
DEVELOPER_EMAIL=

另外需要在你的~/.gradle/gradle.properties下配置如下属性:

SONATYPE_RELEASE_URL=https://oss.sonatype.org/service/local/staging/deploy/maven2
SONATYPE_SNAPSHOT_URL=https://oss.sonatype.org/content/repositories/snapshots
SONATYPE_NEXUS_USERNAME=username for sonatype
SONATYPE_NEXUS_PASSWORD=password for sonatype

LOCAL_RELEASE_URL=私服
LOCAL_SNAPSHOT_URL=私服
LOCAL_USERNAME=私服账号
LOCAL_PASSWORD=私服密码

执行的方法名应该是gradle upload,加-PUsingSonatype是发布到mavenCentral,如果没记错的话。
你可以自己整合下。

from gradle-publish.

 avatar commented on July 2, 2024

非常感谢

from gradle-publish.

Related Issues (16)

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.