Hi,
I’m trying to create a release process with Gradle for our Java-based projects. Most of the things are working properly now but I’m having a problem that I cannot yet resolve. This is mainly around the new Maven Publishing plugin (yes, i’m very well aware it’s incubating still) and the dynamic version of the project.
What I’m trying to achieve is that we never add ‘-SNAPSHOT’ or ‘-RC<0-9>’ to the version but it’s always set to something like ‘3.2.1’ or ‘3.2.2’, then when a taskGraph is ready I am checking if the release task is in the graph and change ‘project.version’ property accordingly, then the project is built and a few other tasks are triggered (such as Git tagging, commiting etc…). Now the only thing that is behaving incorrectly for me is the ‘publish’ task.
I would like to trigger the publish task from either within my ‘release’ task (This would be best, but for some reason ‘tasks[“publish”].execute()’ doesn’t work) or to put it as dependency to my release task (which i can do and it gets triggered) but for ‘publish’ to understand the modified version. I have a feeling that it reads and saves the ‘project.version’ as soon as the publishing extension is configured via
publishing {
publications {
java(MavenPublication) {
from components.java
}
}
repositories {
maven {
if(project.version.endsWith('-SNAPSHOT')) {
name = 'nexus.snapshots'
url 'http://mynexus/nexus/content/repositories/snapshots'
} else {
name = 'nexus.releases'
url 'http://mynexus/nexus/content/repositories/releases'
}
}
}
}
To make it simpler to understand my flow would be like this: When script is initialised, it validates if it’s a release or a dev build, changes versions accordingly and runs publish. After the publish task, if this is a release build - Go through the tagging and version bumping processes and push it all. So basically the only part that is giving me problem is making publish aware and accept the version changes. If my gradle.properties contains ‘version=3.2.1’ and I run a dev build, publication plugin still thinks it’s 3.2.1 and looks for ‘artefact-3.2.1.jar’ even though I’ve changed version in the ‘gradle.taskGraph.whenReady’ to be 3.2.1-SNAPSHOT.
Is there a good way to achieve what I’m trying to do - make publishing aware of my new version without breaking anything else?