Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single version across separate projects in a monorepo #845

Open
tajobe opened this issue Oct 17, 2024 · 3 comments
Open

Single version across separate projects in a monorepo #845

tajobe opened this issue Oct 17, 2024 · 3 comments

Comments

@tajobe
Copy link

tajobe commented Oct 17, 2024

I have a repository which contains multiple gradle projects (not subprojects, but independent builds) and I wish to keep them on the same version.

I understand it is possible to configure the repository path via:

scmVersion {
    repository {
        directory.set(rootProject.file("../").path)
    }
}

...which enables the non-root projects to see the git repo and pick up tags for versioning, however for incrementing and snapshots, it doesn't seem to take any commits outside its path into account. It seems like monorepoConfig is how we should be telling it how to include changes outside its dir when filtering the git log, but setting monorepoConfig.include(listOf(rootProject.file("../").path)) doesn't seem to help. I noticed in jgit that path filters are supposed to be relative to the root of the repository, so I tried using . as an include (eg monorepoConfig.dependenciesDirs.add(".")) to see changes in the whole repo, which also didn't work.

For example, I have a test project with the following layout:

❯ tree
.
├── build.gradle.kts
├── gradle
│   └── wrapper
│       ├── gradle-wrapper.jar
│       └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── project1
    ├── build.gradle.kts
    ├── gradlew
    └── gradlew.bat

4 directories, 8 files

build.gradle.kts:

plugins {
    id("pl.allegro.tech.build.axion-release") version "1.18.13"
}

group = "com.example"
version = scmVersion.version

project1/build.gradle.kts:

plugins {
    id("pl.allegro.tech.build.axion-release") version "1.18.13"
}

scmVersion {
    repository {
        directory.set(rootProject.file("../").path)
    }
}

group = "com.example"
version = scmVersion.version

tasks.wrapper {
    setJarFile("../gradle/wrapper/gradle-wrapper.jar")
}

If I have a v0.1.0 release followed by some commit, eg adding a README to the root, the versions diverge:

❯ ./gradlew release -Prelease.localOnly

> Task :verifyRelease
Looking for uncommitted changes..
Skipping ahead of remote check
Checking for snapshot versions..

> Task :release
Creating tag: v0.1.0
Changes made to local repository only

BUILD SUCCESSFUL in 716ms
2 actionable tasks: 2 executed
❯ touch README.md
❯ git add README.md
❯ git commit -am "Add README"
[main 455a6e5] Add README
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 README.md
❯ ./gradlew currentVersion -q

Project version: 0.1.1-SNAPSHOT
❯ ./gradlew --project-dir project1 currentVersion -q

Project version: 0.1.0

The docs state that a -SNAPSHOT is suffixed when not on a tag, but the project1 version isn't being decorated despite the commit being ahead of the v0.1.0 tag. I'm guessing it has to do with the changes being made outside of the project1 directory, but including the root path via monorepoConfig didn't help, though it's certainly possible I misunderstand its configuration.

How can I get the non-root project to always have the same version?

@tajobe
Copy link
Author

tajobe commented Oct 28, 2024

It seems once the plugin passes the project directory (non-root dir) here, there is no way to back out to the root of the repo with jgit path filters as . does nothing and/ is treated as empty and fails the non-empty check.

Would it be possible to have some flag option in the monorepo config for not passing the project dir?
EG at

if (!includeProjectPath || path.isEmpty()) {

@Olatunji-Longe
Copy link

Olatunji-Longe commented Dec 30, 2024

This issue seems to be addressed on this page ... correct me if that's not what you need.

Look particularly at the section that says

Use the include configuration parameter within a monorepo block to identify dependencies directories that should be added to consideration when calculating whether to increment the version of the parent project.

TLDR:

    scmVersion {
        monorepo {
            include([
                    "common/sdkA",
                    "common/sdkB"
            ])
        }
    }

@tajobe
Copy link
Author

tajobe commented Dec 31, 2024

@Olatunji-Longe That only works for actual submodules, not separate projects. Projects in subdirectories have no way to "escape" the subdir to understand the version, only filters for version incrementing relative to the project. You cannot configure the subproject to use ../, as an example as jgit has no handling of such conventions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants