【问题标题】:Gradle artifactoryPublish won't deploy .jar file generated by spring bootGradle artifactoryPublish 不会部署 spring boot 生成的 .jar 文件
【发布时间】:2016-08-23 09:57:34
【问题描述】:

我正在尝试使用 gradle + artifactory 插件 + maven-publish 插件将 jar + pom 文件部署到 artifactory。

我已经尝试了来自其他来源的多种解决方案,例如 this,我认为 spring-boot 插件正在破坏一些东西(因为它会编辑 jar 文件)

以下脚本成功上传了一个.pom文件,但没有上传spring-boot生成的.jar文件。我怎样才能让它也上传?

这是我的 build.gradle:

buildscript {
    ext {
        springBootVersion = '1.4.0.RELEASE'
    }
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.4.0"
    }
}
apply plugin: 'java'
apply plugin: 'spring-boot'
apply plugin: "com.jfrog.artifactory"
apply plugin: 'maven-publish'
apply from: "gradle/artifactory.gradle"

publishing {
    publications {
        mavenJava(MavenPublication) {
            components.java
        }
    }
}

jar {
    baseName = 'BatchParser'

}

version = '1.0'
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral()
}


dependencies {

    compile('org.projectlombok:lombok:1.16.10')
    ...
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

和 artifactory.gradle

artifactory {
    contextUrl = 'url'
    publish {
        repository {
            repoKey = 'libs-release-local'
            username = 'user'
            password = 'password'
        }
        defaults {
            publications("mavenJava")
        }
    }
}

输出:

gradlew clean build artifactoryPublish


[buildinfo] Not using buildInfo properties file for this build.                  
:clean                      
:compileJava                                                                                                                
:processResources
:classes
:findMainClass
:jar
:bootRepackage                                                                                                        
:assemble
:compileTestJava                                                                  
:processTestResources UP-TO-DATE
:testClasses
:test                                                         
:check
:build
:generatePomFileForMavenJavaPublication                 
:artifactoryPublish
Deploying artifact: http://url/libs-release-local/BatchParser/1.0/BatchParser-1.0.pom
Deploying build descriptor to: http://url/api/build
Build successfully deployed. Browse it in Artifactory under http://url/webapp/builds/BatchParser/1471949957594

【问题讨论】:

  • 您要求 Gradle 运行哪些任务,当您尝试发布时它实际运行的是哪些任务?
  • 我已经添加了命令+输出

标签: gradle spring-boot artifactory


【解决方案1】:

您的publishing 块中有一个非常微妙的错误。缺少from,这导致 Gradle 默默地不将 jar 文件包含在出版物中。您需要更新您的 publishing 块,使其看起来像这样:

publications {
    mavenJava(MavenPublication) {
        from components.java
    }
}

如果我是你,我会为此打开一个 Gradle 可用性错误。默默地什么都不做对用户不太友好。

【讨论】:

  • 哦,哇,这确实相当不友好。感谢您注意到我的错误!
  • 有趣。我在 springboot 添加其内容之前看到了 jar 的发布。推荐使用uploadArchives + mavenDeployer。你们有没有一起工作?
  • 我们在 jenkins 文件中将 build 和 artifactoryPublish 分解为两个单独的 gradle 调用。这导致在没有 springboot 的情况下重新制作 jar。一次调用 build...artifactoryPublish,没有问题
  • > "默默地什么都不做对用户不太友好。"除其他松懈外,无所事事是整个 groovy/gradle 文化的基石之一。大多数 gradle 用户认为这是一项功能(或充其量是附带损害),而不是错误。只是说...
猜你喜欢
  • 1970-01-01
  • 2019-08-23
  • 2020-11-10
  • 2018-09-12
  • 2021-06-01
  • 2020-02-17
  • 1970-01-01
  • 2021-10-13
  • 2013-12-27
相关资源
最近更新 更多