首頁>技術>

將包上傳到 OSSRH 倉庫中需要進行下面的一些配置就可以了。

當你知道配置引數的時候就會非常方便的上傳了,配置的過程也不是很複雜。

匯入外掛

你需要匯入 2 個外掛到 Gradle 專案中。

	id 'maven'	id 'signing'
配置打包任務

如果你使用的是 Java 專案的話,你需要將原始碼和文件都進行打包。

新增下面 2 個打包任務

task javadocJar(type: Jar) {    classifier = 'javadoc'    from javadoc}task sourcesJar(type: Jar) {    classifier = 'sources'    from sourceSets.main.allSource}

然後將程式和程式碼進行壓縮成一個歸檔檔案。

使用下面的命令進行歸檔。

artifacts {    archives javadocJar, sourcesJar}
簽名

要上傳到中央倉庫,簽名是必須的。

新增下面的任務進行簽名

signing {    sign configurations.archives}

同時,你還需要在 C:\Users\yhu.gradle 資料夾中建立一個 gradle.properties 檔案。

根據你的作業系統不同和使用者不同,上面的路徑需要自行調整下。

內容如下。

signing.keyId=YourKeyIdsigning.password=YourPublicKeyPasswordsigning.secretKeyRingFile=PathToYourKeyRingFileossrhUsername=your-jira-idossrhPassword=your-jira-password

根據你引數的不同來進行調整。

有關需要調整的引數和生成的秘鑰等,請參考:Gradle 簽名的配置檔案 gradle.properties 文章中的內容。

設定 Metadata 和上傳

在你的 Gradle 的構建檔案中,定義:

group = "com.example.applications"archivesBaseName = "example-application"version = "1.4.7"

上面的配置就等於是 Maven POM 檔案的包定義了。

然後新增上傳的 Task 到你的 gradle 檔案中。

uploadArchives {  repositories {    mavenDeployer {      beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }      repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {        authentication(userName: ossrhUsername, password: ossrhPassword)      }      snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {        authentication(userName: ossrhUsername, password: ossrhPassword)      }      pom.project {        name 'Example Application'        packaging 'jar'        // optionally artifactId can be defined here         description 'A application used as an example on how to set up           pushing  its components to the Central Repository.'        url 'http://www.example.com/example-application'        scm {          connection 'scm:svn:http://foo.googlecode.com/svn/trunk/'          developerConnection 'scm:svn:https://foo.googlecode.com/svn/trunk/'          url 'http://foo.googlecode.com/svn/trunk/'        }        licenses {          license {            name 'The Apache License, Version 2.0'            url 'http://www.apache.org/licenses/LICENSE-2.0.txt'          }        }        developers {          developer {            id 'manfred'            name 'Manfred Moser'            email '[email protected]'          }        }      }    }  }}

在完成上面所有的配置後,直接執行就可以上傳了,但是需要注意的是,根據你專案的不同,上面的配置引數也是需要一定修改的。

11
最新評論
  • BSA-TRITC(10mg/ml) TRITC-BSA 牛血清白蛋白改性標記羅丹明
  • Gradle 簽名的配置檔案