Tomáš Procházka
10/21/2024, 12:22 PMTYPESAFE_PROJECT_ACCESSORS
has one strange thing.
It generate type safe accessor also for root project folder, why?
When you then try to run such project on TeamCity it fails with
org.gradle.api.InvalidUserDataException: Cannot generate project dependency accessors:
- Cannot generate project dependency accessors because project '55cb9b3dea7c8b39' doesn't follow the naming convention: [a-zA-Z]([A-Za-z0-9\-_])*
Watched directory hierarchies: [/Users/teamcity/buildAgent/work/55cb9b3dea7c8b39]
Because root project folder is 55cb9b3dea7c8b39 in this case.
For me doesn't make sense to make project dependent on the folder name where project was checkouted.
It can be anything.melix
10/21/2024, 12:29 PMrootProject.name = "..."
in your settings.gradle
file. Always set a root project name, or it will, as you noticed, be inferred from the directory name, which usually doesn't make sense.melix
10/21/2024, 12:30 PMmelix
10/21/2024, 12:30 PMTomáš Procházka
10/21/2024, 12:32 PMrootProject
, without specific name.
But how can other projects reference my root project?melix
10/21/2024, 12:33 PMprojects.foo
?melix
10/21/2024, 12:33 PMproject(":")
dependencymelix
10/21/2024, 12:35 PMAlex Semin
10/21/2024, 7:11 PMmelix
10/21/2024, 7:11 PMAlex Semin
10/21/2024, 7:13 PMmelix
10/21/2024, 7:14 PMproject(":")
notation. See also my explanation above.Alex Semin
10/21/2024, 7:26 PMThe root project is a project like any other, it needs to be addressable via an accessor like other projects.The goal of completeness here goes against ergonomics and consistency. Accessors are about explicitly referencing a project and
rootProject
is always there.
There is also a problem of placement. The logical place (for completeness) is to put the root project at the very top of the accessors call hierarchy. But that introduces an unnecessary step to the access of any sub-project. The current design places it on the same level as first-level children, which already hints at complications.
I would also consider today’s Gradle best practice of having a “subproject” even for a single-project builds. Aka having app/build.gradle
structure, instead of just build.gradle
. More so in the actual multi-project builds.melix
10/21/2024, 7:27 PMrootProject
is not a Dependency
, it's a Project
. projects.rootName
is the strict equivalent to project(":")
, not rootProject
.Alex Semin
10/21/2024, 7:31 PMrootProject
can be used to declare a dependency all the same, no?Alex Semin
10/21/2024, 7:33 PMrootProject.name
. Gradle does not have a separate concept of a project display name. That’s why many unsuspecting developers set the root project name just to be displayed in the IDE. This sometimes leads to very unexpected errors stemming from additional format constraints contributed by the accessors machinerymelix
10/21/2024, 7:34 PMProject
instance is historical and probably not something that you'd want (because it leaks state). Similarly the methods which work on Dependency
wouldn't work (e.g variants).Alex Semin
10/21/2024, 7:37 PMprojects
accessor as well as through the root project accessor.melix
10/21/2024, 7:37 PM