Gradle 将工件发布到 Bitbucket

Posted

技术标签:

【中文标题】Gradle 将工件发布到 Bitbucket【英文标题】:Gradle publish artifact to Bitbucket 【发布时间】:2020-05-13 04:37:38 【问题描述】:

我正在尝试使用 gardle 将工件发布到位桶存储库。我正在以gradlew uploadArchives 的身份运行 gradle 任务。它显示 Build 成功,没有任何错误。但是当我签入 bitbucket repo 时,什么都没有。

我不明白我在哪里做错了。

build.gradle:

plugins 
    id 'org.springframework.boot' version '2.2.2.RELEASE'
    id 'io.spring.dependency-management' version '1.0.8.RELEASE'
    id 'java'
    id 'maven'


group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

repositories 
    mavenCentral()
    maven  url "https://plugins.gradle.org/m2/"
    maven  url "https://raw.github.com/synergian/wagon-git/releases"


dependencies 
    implementation 'org.springframework.boot:spring-boot-starter-web'
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-parent', version: '2.2.2.RELEASE'



  task packageSources (type: Jar) 
        from project.sourceSets.main.allSource
        classifier = 'sources'
    

    artifacts 
        archives packageSources
    

    configurations 
        deployerJar
    

    dependencies 
        deployerJar "ar.com.synergian:wagon-git:0.2.3"

    

     uploadArchives 

        configuration = configurations.archives

        repositories.mavenDeployer 

            configuration = configurations.deployerJar

            repository(url: "https://master@bitbucket.org/kotanithin/myrepo.git")
             authentication(userName: "nithinroyal513@gmail.com", password: "xxxxxxxx")
            

             snapshotRepository(url: "https://master@bitbucket.org/kotanithin/myrepo.git")
             authentication(userName: "nithinroyal513@gmail.com", password: "xxxxxxxx")
            

        
    

一些记录我在调试 gradle 任务时观察到的内容

2020-01-28T00:23:03.376+0530 [DEBUG] [org.gradle.api.internal.artifacts.mvnsettings.DefaultLocalMavenRepositoryLocator] No local repository in Settings file defined. Using default path: C:\Users\HP\.m2\repository
2020-01-28T00:23:03.398+0530 [INFO] [org.gradle.api.publication.maven.internal.action.MavenDeployAction] Deploying to https://master://git@bitbucket.org:kotanithin/myrepo.git
2020-01-28T00:23:03.401+0530 [INFO] [org.gradle.api.publication.maven.internal.action.LoggingMavenTransferListener] Downloading: com/example/demo/0.0.1-SNAPSHOT/maven-metadata.xml from repository remote at https://master://git@bitbucket.org:kotanithin/myrepo.git/
2020-01-28T00:23:03.402+0530 [DEBUG] [org.apache.http.client.protocol.RequestAddCookies] CookieSpec selected: compatibility
2020-01-28T00:23:03.403+0530 [DEBUG] [org.apache.http.impl.conn.PoolingHttpClientConnectionManager] Connection request: [route: s->https://master:443][total kept alive: 0; route allocated: 0 of 20; total allocated: 0 of 40]
2020-01-28T00:23:03.403+0530 [DEBUG] [org.apache.http.impl.conn.PoolingHttpClientConnectionManager] Connection leased: [id: 1][route: s->https://master:443][total kept alive: 0; route allocated: 1 of 20; total allocated: 1 of 40]
2020-01-28T00:23:03.403+0530 [DEBUG] [org.apache.http.impl.execchain.MainClientExec] Opening connection s->https://master:443
2020-01-28T00:23:05.955+0530 [DEBUG] [org.apache.http.impl.conn.DefaultManagedHttpClientConnection] http-outgoing-1: Shutdown connection
2020-01-28T00:23:05.955+0530 [DEBUG] [org.apache.http.impl.execchain.MainClientExec] Connection discarded
2020-01-28T00:23:05.955+0530 [DEBUG] [org.apache.http.impl.conn.PoolingHttpClientConnectionManager] Connection released: [id: 1][route: s->https://master:443][total kept alive: 0; route allocated: 0 of 20; total allocated: 0 of 40]
2020-01-28T00:23:05.955+0530 [ERROR] [org.gradle.api.publication.maven.internal.action.LoggingMavenTransferListener] Could not transfer metadata com.example:demo:0.0.1-SNAPSHOT/maven-metadata.xml from/to remote (https://master://git@bitbucket.org:kotanithin/myrepo.git): master
2020-01-28T00:23:05.956+0530 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Completing Build operation 'Execute upload for :uploadArchives'
2020-01-28T00:23:05.956+0530 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Build operation 'Execute upload for :uploadArchives' completed
2020-01-28T00:23:05.956+0530 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Build operation 'Snapshot outputs after executing task ':uploadArchives'' started
2020-01-28T00:23:05.956+0530 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Completing Build operation 'Snapshot outputs after executing task ':uploadArchives''
2020-01-28T00:23:05.956+0530 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Build operation 'Snapshot outputs after executing task ':uploadArchives'' completed
2020-01-28T00:23:05.957+0530 [DEBUG] [org.gradle.api.internal.tasks.execution.ResolveTaskExecutionModeExecuter] Removed task artifact state for task ':uploadArchives' from context.
2020-01-28T00:23:05.957+0530 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Completing Build operation 'Task :uploadArchives'
2020-01-28T00:23:05.905+0530 [LIFECYCLE] [class org.gradle.internal.buildevents.TaskExecutionLogger] 
2020-01-28T00:23:05.905+0530 [LIFECYCLE] [class org.gradle.internal.buildevents.TaskExecutionLogger] > Task :uploadArchives FAILED
2020-01-28T00:23:05.957+0530 [DEBUG] [org.gradle.internal.operations.DefaultBuildOperationExecutor] Build operation 'Task :uploadArchives' completed
2020-01-28T00:23:05.957+0530 [INFO] [org.gradle.execution.plan.DefaultPlanExecutor] :uploadArchives (Thread[Execution worker for ':',5,main]) completed. Took 3.124 secs.
2020-01-28T00:23:05.957+0530 [DEBUG] [org.gradle.execution.plan.DefaultExecutionPlan] Node :uploadArchives failed
2020-01-28T00:23:05.957+0530 [DEBUG] [org.gradle.execution.plan.DefaultExecutionPlan] Node :uploadArchives completed, executed: true

当我将 url 更改为下面并且我的主要分支 bitbucket 是发布时

https://kotanithin@bitbucket.org/kotanithin/demo.git

错误:

020-01-28T11:15:14.572+0530 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE: Build failed with an exception.
2020-01-28T11:15:14.572+0530 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 
2020-01-28T11:15:14.573+0530 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * What went wrong:
2020-01-28T11:15:14.573+0530 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Execution failed for task ':uploadArchives'.
2020-01-28T11:15:14.573+0530 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > Could not publish configuration 'archives'
2020-01-28T11:15:14.573+0530 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]    > Could not deploy to remote repository | Failed to deploy artifacts: Could not find artifact com.example:demo:jar:0.0.1-20200128.053924-1 in remote (https://kotanithin@bitbucket.org/kotanithin/demo.git)
2020-01-28T11:15:14.573+0530 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 
2020-01-28T11:15:14.574+0530 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Try:
2020-01-28T11:15:14.574+0530 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]  Run with --scan to get full insights.
2020-01-28T11:15:14.574+0530 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] 
2020-01-28T11:15:14.574+0530 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * Exception is:
2020-01-28T11:15:14.576+0530 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':uploadArchives'.
2020-01-28T11:15:14.576+0530 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]   at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:187)
2020-01-28T11:15:14.576+0530 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]   at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:263)
2020-01-28T11:15:14.576+0530 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]   at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeIfValid(ExecuteActionsTaskExecuter.java:185)

【问题讨论】:

【参考方案1】: 首先,将本地存储库与 bitbucket 同步。 进入你的电脑临时目录,寻找 wagon-git-ea4656fb6sqs59713497... 喜欢目录并将它们全部删除。 然后重试gradlew uploadArchives

【讨论】:

以上是关于Gradle 将工件发布到 Bitbucket的主要内容,如果未能解决你的问题,请参考以下文章

重新发布 gradle 工件

使用 Gradle 将工件上传到 JFrog Artifactory

使用 gradle 发布到 maven 时删除附加到工件名称的默认 date.time

Android Gradle 插件将自定义 Gradle 插件上传到自建 Maven 仓库 ③ ( 配置上传工件 | 将 Gradle 插件 jar 包源码文档上传到本地Maven 仓库 )

没有使用 jenkins gradle artifactory 插件部署的工件

如何使用 gradle API 检查工件是不是存在?