I have a project for which I have to upload YAML files into artifactory. I want them to be located at a specific path in artifactory, but I want to determine the full name myself without the artifactId present in the name.
What I have
plugins {
`maven-publish`
}
group = "com.example"
version = "0.0.1-SNAPSHOT"
repositories {
mavenLocal()
}
// Example task for generating YAML files.
tasks.register("generateSomething") {
doLast {
buildDir.resolve("generated").mkdir()
buildDir.resolve("generated/my-st-$version.yml").writeText("I am file for ST")
buildDir.resolve("generated/my-prd-$version.yml").writeText("I am file for PRD")
}
}
project.tasks.withType(AbstractPublishToMaven::class.java) {
dependsOn("generateSomething")
}
publishing {
publications {
create<MavenPublication>("my-own-artifacts") {
artifact(buildDir.resolve("generated/my-st-$version.yml")) {
classifier = "st"
extension = "$version.txt"
}
artifact(buildDir.resolve("generated/my-prd-$version.yml")) {
classifier = "prd"
extension = "$version.txt"
}
}
}
}
When I run gradle publishToMavenLocal
(artifactId is test-example), I get the following files inside repository\com\example\test-example\0.0.1-SNAPSHOT\
.
test-example-0.0.1-SNAPSHOT-prd.0.0.1-SNAPSHOT.yml
test-example-0.0.1-SNAPSHOT-st.0.0.1-SNAPSHOT.yml
But what I want is:
prd.0.0.1-SNAPSHOT.yml
st.0.0.1-SNAPSHOT.yml
What I tried
I have tried changing the artifactId to my-st
, but this leads to the path changing to com\example\my-set\...
, which is not what I want. I also tried playing around with classifier and extension, but it always prefixes the name with things I don't want.
I don't see any other methods I have available in the MavenPublish class.
I checked the code in AbstractMavenPublisher.java
, and it may be that it is not possible at all:
/**
* Publishes a single module artifact, based on classifier and extension.
*/
void publish(String classifier, String extension, File content) {
StringBuilder path = new StringBuilder(128);
path.append(groupPath).append('/');
path.append(artifactId).append('/');
path.append(moduleVersion).append('/');
path.append(artifactId).append('-').append(artifactVersion);
if (classifier != null) {
path.append('-').append(classifier);
}
if (extension.length() > 0) {
path.append('.').append(extension);
}
ExternalResourceName externalResource = new ExternalResourceName(rootUri, path.toString());
publish(externalResource, content);
}
But I am not sure if this is the code that is actually called. Maybe there are other ways to publish?