I'm trying to publish an artifact to a corporate repository. I set up the maven-publish plugin as follows (I use build.gradle.kts):
plugins {
`java-library`
`maven-publish`
}
val nexusUsername: String by project
val nexusPassword: String by project
val nexusSnapshotRepositoryUrl: String by project
val nexusRepositoryUrl: String by project
publishing {
publications {
register("mavenJava", MavenPublication::class) {
from(components["java"])
}
}
repositories {
maven {
credentials {
username = nexusUsername
password = nexusPassword
}
url = uri(nexusRepositoryUrl)
mavenContent {
releasesOnly()
}
}
maven {
credentials {
username = nexusUsername
password = nexusPassword
}
url = uri(nexusSnapshotRepositoryUrl)
mavenContent {
snapshotsOnly()
}
}
}
}
gradle.properties:
version=0.0.1
nexusRepositoryUrl=https://nexus.custom/repository/release/
nexusSnapshotRepositoryUrl=https://nexus.custom/repository/snapshot/
nexusUsername=
nexusPassword=
For some reason, when the publish task is called, mavenContent is ignored for me - the publication always tries to execute to the last maven repository, which is specified ignoring the version (i.e., the application version is 0.0.1, while the publication is carried out in the snapshot repository, if the repositories are swapped, the publication will be in the release repository). I'm expecting a behavior in which when I run the publish task, I will have the correct repository determined based on the version, is this not how it should work?
When I start the task, I get information in the log about an attempt to publish to the repository snapshots:
./gradlew publish
Execution failed for task ':publishMavenJavaPublicationToMaven2Repository'. Failed to publish publication 'mavenJava' to repository 'maven2' Could not PUT 'https://nexus.custom/repository/snapshot/ru/example/0.0.1/some-example-app-0.0.1.jar'. Received status code 400 from server: Bad Request