Crimix / ChangedProjectsTaskPlugin

A Gradle plugin to run a user defined task on changed projects (modules) and their dependent projects (modules)
https://plugins.gradle.org/plugin/io.github.crimix.changed-projects-task
MIT License
8 stars 2 forks source link

Duplicate key error when running `runTaskForChangedProjects` #8

Closed dennisameling closed 2 years ago

dennisameling commented 2 years ago

Thanks for creating this plugin!

We have several projects that have the common name, e.g. demo-common, demo2-common, etc. - this seems to be causing issues when running ./gradlew runTaskForChangedProjects -PchangedProjectsTask.run:

java.lang.IllegalStateException: Duplicate key common (attempted merging values ProjectNode[project=project ':common', childNodes={}] and ProjectNode[project=project ':demo-common', childNodes={}])
        at io.github.crimix.changedprojectstask.utils.ProjectNode.<init>(ProjectNode.java:21)
        at io.github.crimix.changedprojectstask.providers.ProjectDependencyProvider.<init>(ProjectDependencyProvider.java:35)
        at io.github.crimix.changedprojectstask.task.ChangedProjectsTask.configureAfterAllEvaluate(ChangedProjectsTask.java:83)
        at io.github.crimix.changedprojectstask.task.ChangedProjectsTask.lambda$configureAndRun$0(ChangedProjectsTask.java:41)
        at org.gradle.configuration.internal.DefaultUserCodeApplicationContext$CurrentApplication$1.execute(DefaultUserCodeApplicationContext.java:123)
        at org.gradle.configuration.internal.DefaultListenerBuildOperationDecorator$BuildOperationEmittingAction$1.run(DefaultListenerBuildOperationDecorator.java:152)
        at org.gradle.internal.operations.DefaultBuildOperationRunner$1.execute(DefaultBuildOperationRunner.java:29)

Do you have any clues on how we could get this resolved? Thanks in advance!

Crimix commented 2 years ago

How is the project structured? Both in terms of Gradle subprojects and directories as I have not been able to replicate the problem locally.

The error seems to suggest that there are two subprojects with the same directory name and same Gradle project parent

dennisameling commented 2 years ago

Thanks for your quick reply! Looked a bit further into this and it looks like our project structure in settings.gradle.kts is triggering this error:

include(":common")
project(":common").projectDir = file("common")

include(":contoso-common")
project(":contoso-common").projectDir = file("brands/contoso/common")

include(":demo-common")
project(":demo-common").projectDir = file("brands/demo/common")

Both of the projectDirs end with common in their directory paths. When I rename the first path to commonn for example, it works correctly.

We have ~15 modules in our actual settings.gradle.kts file and would prefer not having to update all the paths. Is this a scenario you're planning on supporting? Thanks in advance! 🙏🏼

Crimix commented 2 years ago

I will have a look at fixing it to be more robust, such that it can support this scenario.

Crimix commented 2 years ago

The code should no be more robust and less naive, as of 1.5 it should be able to support this scenario and possible others that I had not thought about when I made the first implementation