Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle: How do I publish a custom file artifact?

Gradle Version: 3.5

I am trying to publish my custom RPM artifact, but the documentation is really unclear about how this should be done.

This is an excerpt from our publishing gradle script:

project(':path:to:rpm:project') {

    apply plugin: "java"
    apply plugin: "maven-publish"

    publishing {
        repositories {
            maven {
                credentials {
                    username 'aaa'
                    password 'sss'
                }
                url "https://url/to/repository"
            }
        }

        publications {
            pub(MavenPublication) {
                artifact 'our-software-rpm' {

                }
            }
        }
    }

    task rpmArtifact(dependsOn: 'installerMakeRpm') {
        ext.rpmfile = file("$project.buildDir/tmp/rpmbuild/RPMS/x86_64/our-software.x86_64.rpm")
    }

    artifacts {
        archives(rpmArtifact.rpmfile) {
            name 'our-software-rpm'
            type 'rpm'
            builtBy rpmArtifact
        }
    }

    assemble.dependsOn rpmArtifact
}

I am unsure how I should reference the custom RPM artifact in the publications closure. Using the artifact name ('our-software-rpm') does not work, using the name of the task (rpmArtifact) does not work either. So what should I do?

Also, the project applies the java plugin to get an ArtifactHandler that actually can accept file artifacts - the DefaultArtifactHandler does not work for that. Is there a better option, because the project really is not a java project and I would prefer not to apply a plugin I don't really need.

like image 582
cornergraf Avatar asked Oct 02 '17 10:10

cornergraf


1 Answers

I received a vague hint on the gradle issues list, and the following solution ended up working for me:

Note that I still have the undesired java plugin declaration, I found no solution for that.

project(':Release:Installers:OurProject:Linux:our-project') {

    apply plugin: 'java'

    def myRpm = artifacts.add('archives', file("$project.buildDir/rpm/our-project-${productInfo.ai_version}.x86_64.rpm")) {
        builtBy('installerMakeRpm') 
    }

    publishing {
        publications {
            pub(MavenPublication) {
                artifact myRpm
                artifactId "our-project-installer-linux"
                groupId 'com.company.ourproject'
                version productInfo.release_tag
            }
        }
    }
}
like image 149
cornergraf Avatar answered Jan 01 '23 09:01

cornergraf