gradle suproject version is unspecified while publishing

Viewed 1140

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?

2 Answers

I am working on multimodule projects with gradle and we are not setting a version in submodules.All we do is setting it in base project in gradle.properties file.

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

then you can use it:

url = project.version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl

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

Related