Search code examples
javagradlegradle-plugin

gradle suproject version is unspecified while publishing


i have two nexus repositories: one for releases, other for snapshots. i have code in publish task to define which repo to pick according to doc:

        repositories {
            repositories {
                maven {
                    credentials {
                        username "$nexusUser"
                        password "$nexusPassword"
                    }
                    def releasesRepoUrl = "https://xxx/repository/factoring-maven-release/"
                    def snapshotsRepoUrl = "https://xxx/repository/factoring-maven-snapshots/"
                    url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
                }
            }
            publications {
                create("default", MavenPublication.class) {
                    from(components["java"])
                }
            }
        }
    }

and subprojects included by this code :

rootProject.name = 'xxx-integration-lib'

include 'xxx-service1-dto'
include 'xxx-service2-dto'

subprojects build.gradle:

group = "xxx"
version = "0.0.6-SNAPSHOT"

but this doesnt work since subproject version is always unspecified. tried:

  1. making new allproject task to return version
  2. using project.property('propName') - but this seems like a workaround, not a solution

any thoughts?


Solution

  • the only worked way for me was a workaround: placing subproject version management in root build.gradle like this

    project(':subproject1') {
        version '0.0.6-SNAPSHOT'
    }
    
    project(':subproject2') {
        version '0.0.12-SNAPSHOT'
    }
    
    project(':subproject14) {
        version '0.0.5-SNAPSHOT'
    }
    

    and then project.version property is being injecting correctyl