Roldan Galan
08/20/2024, 3:45 PMRoldan Galan
08/20/2024, 3:45 PMproject-1
โโโ build.gradle
project-1-api
โโโ build.gradle
project-2
โโโ build.gradle
I would like to refactor it to the following structure:
project-1
โโโ build.gradle
โโโ api
โ โโโ build.gradle
project-2
โโโ build.gradle
So I simply want to move the api module inside the project-1 module.
The project-2 depends on project-1 api. This works in the original structure but as soon as I move project-1-api inside project-1 I am unable to compile project-2, as it cannot resolve any references.
Interestingly, project-1 also depends project-1:api, and it compiles fine after this refactor. ๐ค This really puzzles me. I would expect this won't work either.
I've updated the both project-1 and project-2 build.gradle files, and also the root settings.gradle file accordingly replacing project-1-api by project-1:api. (as the identifier changes with this movement).
I've verified that project-1:api builds transitively when project-2 attempts to compile, so it looks like the dependency is properly declared at Gradle level.Roldan Galan
08/20/2024, 3:45 PMproject-1
โโโ impl
โ โโโ build.gradle
โโโ api
โ โโโ build.gradle
project-2
โโโ build.gradle
In this case both project-1 modules coexist in a folder that is not an actual module (so no build.gradle, or sourcesets inside).
Which brings me to question if declaring modules inside other modules is what is causing the issues. Anyone can clarify if is there any actual limitation for this practice? ๐TrevJonez
08/20/2024, 4:11 PMVampire
08/20/2024, 5:14 PMapi-1.2.3.jar which might be "suboptimal". So you might want the project name to be project1-api but set the project directory to be project1/api if you don't want to have project1/project1-api.Roldan Galan
08/20/2024, 5:30 PMapi when moving inside the other module for exactly the naming situation.
Ok, if this should work in theory, then I will keep trying to figure out what is wrong. I wanted to validate that this is not an antipattern or an incorrect configuration.
I will provide an example if I cannot unblock.
Thanks for the quick insights!Vampire
08/20/2024, 7:50 PMGasper Kojek
08/21/2024, 7:52 AMVampire
08/21/2024, 8:11 AMRoldan Galan
08/23/2024, 8:45 AMRoldan Galan
08/23/2024, 8:53 AMimplementation(project(":project-1:api")) , which contains all the relevant information to differentiate them.
Doing implementation(project(":project-1:project-1-api")) would be quite redundant to me, and I would like to avoid forcing to rename each module (we have many and is an extra requirement when creating more).
This is why I would like to name each one simply as api and let them inherit their parent ๐Roldan Galan
08/23/2024, 8:53 AMRoldan Galan
08/23/2024, 9:27 AMproject-1:api. In the moment I add a second submodule in a different path named also api, such as project-2:api , any other module requiring both fails to compile! ๐คฏ
Is this expected/known? I can report this as GH issue with a code example to make it more clear.Vampire
08/23/2024, 2:15 PMapi-1.2.3.jar.
So even if compiling would work, when you then put mutliple of those to a classpath, how should that work? ๐
You might be able to mitigate it in your situation by just configuring the Jar tasks to produce different names by setting the archiveName or archiveBaseName or archiveClassifier so that your resulting jar names are unique.Roldan Galan
08/23/2024, 2:34 PMproject(":project-1-api").projectDir = file("project-1/api") , which I guess effectively changes also that the archive name indirectly. Not sure if is there any preference for any these two approaches?Vampire
08/23/2024, 2:48 PMthey would be identified as different ones by the different pathThey should, yes, unless in the end you try to put them to the same directory for example as is typical for a normal application. No idea about Android builds though, Android is always a bit special. ๐
I solved this by renaming the module in the settings.kts fileWhich is exactly what I suggested above. ๐
TrevJonez
08/23/2024, 2:54 PMTrevJonez
08/23/2024, 2:54 PM