gradle suproject version is unspecified while publishing
Asked Answered
D

3

6

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?

Dosser answered 9/7, 2020 at 13:24 Comment(0)
D
3

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

Dosser answered 13/7, 2020 at 6:59 Comment(0)
Y
0

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
Yeanling answered 9/7, 2020 at 14:6 Comment(2)
well this doesnt answer the questionDosser
OK, you are right. One thing you can try is to add - before SNAPSHOT. url = project.version.endsWith('-SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrlYeanling
B
-1

Instead of using this

publishing {
    publications {
        nexus(MavenPublication) {
            from components.java
        }
    }
    repositories {
        maven {
            def releasesRepoUrl = 'https://.../releases/'
            def snapshotsRepoUrl = 'https://.../snapshots/'
            url = project.version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl

            credentials {
                ...
            }
        }
    }
}

use afterEvaluate block outside of publications and repositories block.

publishing {
    afterEvaluate {
        publications {
            nexus(MavenPublication) {
                from components.java
            }
        }
        repositories {
            maven {
                def releasesRepoUrl = 'https://.../releases/'
                def snapshotsRepoUrl = 'https://.../snapshots/'
                url = project.version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl

                credentials {
                    ...
                }
            }
        }
    }
}
Barboza answered 20/4, 2023 at 19:36 Comment(1)
it doesn't workHumpy

© 2022 - 2024 — McMap. All rights reserved.