Gradle: How do I publish a custom file artifact?
Asked Answered
V

1

8

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.

Vince answered 2/10, 2017 at 10:22 Comment(0)
V
8

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
            }
        }
    }
}
Vince answered 16/10, 2017 at 7:43 Comment(1)
Thank you, dude, it really works. Gradle version: 7.5 In my case event without "builtBy('installerMakeRpm')" rowCabalistic

© 2022 - 2024 — McMap. All rights reserved.