Search code examples
spring-bootgradleteamcityartifactoryrelease-management

How can I have Teamcity Artifactory plugin invoke bootJar instead of Jar in Gradle?


We are using Gradle 4.8.1 to generate Spring Boot executable jars. This works fine locally. However, we are using Teamcity to publish our artifacts into Artifactory.

The issue is, to my understanding, that the "artifactoryPublish" task invokes the "jar" task in Gradle, which uploads artifacts from "Archives". So, irrespective of whether teamcity invokes the "assemble" task, or the "bootjar" task, or the "build" task, the artifactory plugin is taking the output of the "jar" task in the end and publishes that, whereas we'd like to have the output of the "bootjar" task (fat jar) in artifactory.

Is there any way I can force artifactoryPublish to run bootjar instead of jar ? Or for the jar task to create a fat jar as well ? Or should I consider another approach ?

Here's my build.gradle from one of the subprojects

plugins {
    id "org.springframework.boot" version "2.0.4.RELEASE"
    id "io.spring.dependency-management" version "1.0.6.RELEASE"
}

apply plugin: 'java'

repositories {
    mavenCentral()
}

description = 'atlas-data-service'

// Dynamically insert TeamCity build number if available
if (hasProperty("teamcity")) {
    version = teamcity["build.number"]
    println "Release version with TeamCity build number passed into gradle is " + version
} else {
    // Take the default appVersion defined in top level build.gradle when building outside of TeamCity
    version = "$appVersion"
}

jar {
    baseName = 'data-service'
    enabled = true
}

bootJar {
    mainClassName = 'c.m.f.a.dataservice.AtlasDataServiceApplication'
    baseName = 'data-service'
    enabled = true
    classifier = 'boot'
}

dependencies {
...
}

Solution

  • This question is from last year, but updating in case someone else comes looking with the same issue.

    I used the Maven-publish plugin to get the job done.

    https://docs.spring.io/spring-boot/docs/current/gradle-plugin/reference/html/#publishing-your-application-maven-publish

    apply plugin: 'maven-publish'
    
    publishing.publications {
        bootJava(MavenPublication) {
            artifact bootJar
        }
    }