From eec9bf5b35588bbe74df4782c833e77bdb893eb7 Mon Sep 17 00:00:00 2001 From: Mike Cumings Date: Tue, 1 Oct 2024 10:04:59 -0700 Subject: [PATCH] Prevent integration failure when graph-analytics-plugin is not applied (#38) Ensures that graph-analytics-plugin code references are only in play when the plugin has been applied. Updates the docs to clarify the requirement to separately apply the other plugin. --- .../develocity/projectcost/ProjectCostPlugin.kt | 16 ++++++++-------- .../metrics/develocity/projectcost/README.md | 17 ++++++++++------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/main/kotlin/com/ebay/plugins/metrics/develocity/projectcost/ProjectCostPlugin.kt b/src/main/kotlin/com/ebay/plugins/metrics/develocity/projectcost/ProjectCostPlugin.kt index bbafb2d..4d7b738 100644 --- a/src/main/kotlin/com/ebay/plugins/metrics/develocity/projectcost/ProjectCostPlugin.kt +++ b/src/main/kotlin/com/ebay/plugins/metrics/develocity/projectcost/ProjectCostPlugin.kt @@ -83,15 +83,15 @@ internal class ProjectCostPlugin @Inject constructor( val projectCostGraphAnalysis = providerFactory.gradleProperty(GRAPH_ANALYSIS_ENABLED_PROPERTY).orNull.toBoolean() if (projectCostGraphAnalysis) { - val reportDuration = providerFactory.gradleProperty(GRAPH_ANALYSIS_DURATION_PROPERTY).orElse("P7D").get() - val reportTaskProvider = reportTaskProviderFun.invoke(reportDuration) - val graphAnalysisTask = project.tasks.register("projectCostGraphAnalysis-$reportDuration", ProjectCostGraphAnalysisTask::class.java) - graphAnalysisTask.configure { task -> - with(task) { - projectReportProperty.set(reportTaskProvider.flatMap { it.reportFile }) - } - } project.plugins.withId("com.ebay.graph-analytics") { + val reportDuration = providerFactory.gradleProperty(GRAPH_ANALYSIS_DURATION_PROPERTY).orElse("P7D").get() + val reportTaskProvider = reportTaskProviderFun.invoke(reportDuration) + val graphAnalysisTask = project.tasks.register("projectCostGraphAnalysis-$reportDuration", ProjectCostGraphAnalysisTask::class.java) + graphAnalysisTask.configure { task -> + with(task) { + projectReportProperty.set(reportTaskProvider.flatMap { it.reportFile }) + } + } project.extensions.getByType(GraphExtension::class.java).apply { analysisTasks.add(graphAnalysisTask) } diff --git a/src/main/kotlin/com/ebay/plugins/metrics/develocity/projectcost/README.md b/src/main/kotlin/com/ebay/plugins/metrics/develocity/projectcost/README.md index c475080..d5044c0 100644 --- a/src/main/kotlin/com/ebay/plugins/metrics/develocity/projectcost/README.md +++ b/src/main/kotlin/com/ebay/plugins/metrics/develocity/projectcost/README.md @@ -35,15 +35,18 @@ performed by the [eBay Graph Analytics Plugin](https://github.com/eBay/graph-ana This integration allows for the resulting project graph data to include the execution-time costs for each project module, granting a more comprehensive picture of the project's build. -To enable the integration, the gradle property `projectCostGraphAnalysisEnabled` must be -set to `true`. Since the data gathering phase for the project cost summarizer can be quite +To enable the integration, the following must be done: +- The gradle property `projectCostGraphAnalysisEnabled` must be set to `true`. This activates the code + which performs the integration work. +- The `graph-analytics-plugin` must be (separately) applied to the project. This makes the implementation + available to the project, allowing the integration to be performed. +- The `projectCostGraphAnalysisDuration` property may be set to a valid Java time duration string. + This specifies the duration of time over which the project cost data will be aggregated. If not + specified, the default value of `P7D` (7 days) will be used. + +Since the data gathering phase for the project cost summarizer can be quite expensive to gather, it is recommended to run this integration in a dedicated job. -Additionally, since the project cost reporting aggregates data over a period of time, the -duration for the report must be specified. This is done by setting the -`projectCostGraphAnalysisDuration` property to a Java time duration string. If not specified, -data form the last 7 days will be used. - Putting it all together, the following command can be used to generate a graph analysis incorporating the project cost data over a custom time range of 3 days: