How to configure version for dependencies in POM file?


(Anders Brolien) #1

Let’s say I have two gradle modules with project dependencies between each other. Module A depends on Module B.

When building and installing A the pom file for A will include a dependency referring to B and the current version of B, let’s say 1.0.0. If I then produce a new version of B, let’s say 1.0.1 the POM file for A still refers to version 1.0.0 of B.

Is there any way to configure the dependency declaration in the POM file for A so that it would say 1.0.+?


(Anders Brolien) #2

I managed to find a solution to this on own:

tasks.withType(Upload) { task ->
                task.repositories.each {repo ->
                    repo.pom.whenConfigured {pom ->
                        pom.dependencies.each {dep ->
                            if (VersionHelper.isChanging(dep.version)) {
                                def newVersion = dep.version[0..-3] + '+'
                                println "Changing pom version for artifact $dep.artifactId to $newVersion was $dep.version"
                                dep.version = newVersion
                            }
                        }
                    }
                }
            }

Any comments on this solution?