Skip to content

Primary graph is always generated even when only graph blocks are configured #70

Description

@MattSkala

The README states:

If using only graph calls, then the Primary Graph doesn't need to be setup at all! You can see this in the samples above.

In practice (v0.13.0), the primary graph is always emitted — into the root README.md under # Module Graph
even when the moduleGraphConfig block contains only graph calls and no top-level primary
properties.

Reproduction

  plugins {                                                                                                    
      id("dev.iurysouza.modulegraph") version "0.13.0"                                                       
  }                                                                                                            
   
  moduleGraphConfig {                                                                                          
      graph(                                                                                                 
          readmePath = "./docs/MODULE_GRAPHS.md",
          heading = "## My Custom Graph",                                                                      
      ) {
          orientation = Orientation.LEFT_TO_RIGHT                                                              
          theme = Theme.NEUTRAL                                                                                
          rootModulesRegex = "^:app$"            
      }                                                                                                        
  }                                                                                                          

Run ./gradlew createModuleGraph.

Expected: only docs/MODULE_GRAPHS.md is updated; README.md is untouched.

Actual: README.md is rewritten with a # Module Graph section containing the full project graph, in addition
to the configured docs/MODULE_GRAPHS.md output.

Root cause

In ModuleGraphPlugin.getPrimaryGraphConfig(), the primary readmePath and heading are read with fallback
defaults before the "any configured?" check:

  val readmePath = task.readmePath.orNull                                                                    
      ?: task.project.rootDir.resolve("README.md").absolutePath                                                
  val heading = task.heading.orNull ?: "# Module Graph"
  // …                                                                                                         
  val params: List<Any?> = listOf(readmePath, heading, theme, orientation, …)                                
  val hasPrimaryConfig = params.any { it != null }                                                             
  if (!hasPrimaryConfig) return null                                                                         

Because readmePath and heading are seeded with non-null defaults and then included in params, hasPrimaryConfig is always true. The "skip primary graph" branch is unreachable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions