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.?
File aFileObject = new File( 'path/to/file/generated/by/external/tool' )
publishing {
publications {
thePublication( MavenPublication ) {
groupId 'some.group' // defaults to project.group
artifactId 'xyz' // defaults to project.name
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
}
}
}
}
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.
@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.