Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,39 @@ moduleGraphConfig {

If you don't set `rootModulesRegex`, all modules will be considered root modules and cannot be excluded, even if they match `excludedModulesRegex`.

## Providing a Custom Graph Model

Per default, the plugin generates a graph from the relationships between Gradle modules in your project. You can also extend the task to render graphs from custom data for example, to visualize third-party dependencies or other non-project relationships.

Here's a basic example of how to create a custom graph model by registering a new task of type `CreateModuleGraphTask`:

```kotlin
import dev.iurysouza.modulegraph.gradle.CreateModuleGraphTask
import dev.iurysouza.modulegraph.gradle.Module
import dev.iurysouza.modulegraph.ModuleType
import dev.iurysouza.modulegraph.model.GraphConfig
import dev.iurysouza.modulegraph.model.GraphParseResult

tasks.register<CreateModuleGraphTask>("customModuleGraph") {
// Build your custom graph model
val moduleA = Module(":alpha", null, ModuleType.JavaLibrary())
val moduleB = Module(":beta", null, ModuleType.Unknown())

val fullGraph = linkedMapOf(
moduleA to listOf(moduleB)
)

// Configure the graph
val builder = GraphConfig.Builder("README.md", "Custom Module Graph")
builder.showFullPath = true
val config = builder.build()

// Set the custom graph model and project directory as task inputs
graphModels.set(listOf(GraphParseResult(fullGraph, config)))
projectDirectory.set(project.layout.projectDirectory)
}
```

## Contributing 🀝

Feel free to open an issue or submit a pull request for any bugs/improvements.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ abstract class CreateModuleGraphTask : DefaultTask() {

@get:Input
@get:Option(option = "graphModels", description = "The produced graph models")
internal abstract val graphModels: ListProperty<GraphParseResult>
abstract val graphModels: ListProperty<GraphParseResult>

@get:OutputDirectory
@get:Option(option = "projectDirectory", description = "The root project directory")
internal abstract val projectDirectory: DirectoryProperty
abstract val projectDirectory: DirectoryProperty

@get:Input
@get:Option(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import java.io.Serializable as JavaSerializable
import kotlinx.serialization.Serializable

@Serializable
internal data class Module(
data class Module(
val path: String,
val configName: String? = null,
val type: ModuleType = ModuleType.Java(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ data class GraphConfig(
*/
var nestingEnabled: Boolean? = null

internal fun build(): GraphConfig {
fun build(): GraphConfig {
return GraphConfig(
readmePath = readmePath,
heading = heading,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import java.io.Serializable as JavaSerializable
import kotlinx.serialization.Serializable

@Serializable
internal data class GraphParseResult(
data class GraphParseResult(
/** The output graph model after parsing */
val graph: ProjectGraph,
/** The original config provided used to produce [graph] */
Expand Down
Loading