Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle artifactoryPublish won't deploy .jar file generated by spring boot

I'm trying to deploy a jar + pom file to artifactory using gradle + artifactory plugin + maven-publish plugin.

I've tried multiple solutions from other sources like this and I think the spring-boot plugin is breaking stuff (because it edits the jar file)

The following script successfully uploads a .pom file, but not the .jar file generated by spring-boot. How can I get it to also upload that?

this is my 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')
}

and artifactory.gradle

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

output of:

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
like image 619
p.streef Avatar asked Aug 23 '16 09:08

p.streef


1 Answers

There's a very subtle mistake in your publishing block. from is missing which is causing Gradle to silently not include the jar file in the publication. You need to update your publishing block so that it looks like this:

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

If I were you, I'd open a Gradle usability bug for this. Silently doing nothing isn't very user friendly.

like image 158
Andy Wilkinson Avatar answered Nov 15 '22 04:11

Andy Wilkinson