Publishing a proprietary archive using maven-publish

I am trying to incorporate an “external to Gradle” build process into the Gradle ecosystem. The external process goes through and generates a package with a non-standard extension name (let’s just say it’s “.ext”), but in reality, the file is a zip file.

I will eventually (hopefully) rip open this external process and claim it for Gradle… but for now, I’d like to still publish this artifact using maven-publish the way I publish all our other artifacts.

I have no way to control the name of the file generated by this external process… unless I rename it.

So my question… can I register an external file as an artifact, even though it doesn’t have standard publication naming? And if so… during the publication… will maven-publish “rename” the file using the artifact id, group, version, etc.?

Thank you.

Try something like:

File aFileObject = new File( 'path/to/file/generated/by/external/tool' )
publishing {
    publications {
        thePublication( MavenPublication ) {
            groupId '' // defaults to
            artifactId 'xyz'  // defaults to
            version '1.2.3' // defaults to project.version

            artifact( aFileObject ) {
                classifier = 'abc' // if you actually need the classifier (ie, when you have multiple artifacts)
                extension = 'ext' // gradle will try to infer this from aFileObject, but you can override it
                // can wire up task dependencies
                builtBy someTask

Some helpful links:

1 Like

A+ Chris. Thank you very much.

It’s highly suggested that you do not use new File() inside a build script with relative paths. There’s no guarantee that the working directory is what you think it will be. You should use project.file() instead. This ensures that relative paths are always resolved relative to the current project directory.

artifact(file('path/to/my/')) { ... }

I completely agree with Mark’s recommendation.

I’ll also add that in many cases the artifact of a publication should be the output of a task.
If the task is not an AbstractArchiveTask:

artifact( tasks.someTask.outputs.singleFile ) {
    builtBy tasks.someTask

or if the task is an AbstractArchiveTask:

artifact( tasks.someTask )

@mark_vieira Is there any interest in having a shortcut in Gradle that handles non-AbstractArchiveTask’s in the manner I show above? If so, perhaps it’s something I could look at providing a pull request for.

+1 to artifact(tasks.someTask)

It was what I tried first, since copy tasks automatically handle that as well.