@@ -305,8 +305,9 @@ tasks {
305305
306306 val removeLicenseDate by registering {
307307 // removing the license report date makes it idempotent
308+ val rootDirPath = rootDir.toPath()
308309 doLast {
309- val filePath = rootDir.toPath() .resolve(" licenses" ).resolve(" licenses.md" )
310+ val filePath = rootDirPath .resolve(" licenses" ).resolve(" licenses.md" )
310311 if (Files .exists(filePath)) {
311312 val datePattern =
312313 Pattern .compile(" ^_[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} .*_$" )
@@ -321,19 +322,27 @@ tasks {
321322 }
322323 }
323324
324- val generateLicenseReportEnabled =
325+ val generateLicenseReportEnabled = providers.provider {
325326 gradle.startParameter.taskNames.any { it.equals(" generateLicenseReport" ) }
326- named(" generateLicenseReport" ).configure {
327+ }
328+ val generateLicenseReportTask = named(" generateLicenseReport" )
329+ generateLicenseReportTask.configure {
327330 dependsOn(cleanLicenses)
328331 finalizedBy(" :spotlessApply" )
329332 finalizedBy(removeLicenseDate)
330333 // disable licence report generation unless this task is explicitly run
331334 // the files produced by this task are used by other tasks without declaring them as dependency
332335 // which gradle considers an error
333- enabled = enabled && generateLicenseReportEnabled
336+ enabled = enabled && generateLicenseReportEnabled.get()
337+ // License report plugin is not configuration cache compatible
338+ // https://github.com/jk1/Gradle-License-Report/issues/280
339+ notCompatibleWithConfigurationCache(" License report plugin uses Project at execution time" )
334340 }
335- if (generateLicenseReportEnabled) {
336- project.parent?.tasks?.getByName(" spotlessMisc" )?.dependsOn(named(" generateLicenseReport" ))
341+ val parentSpotlessMiscTask = project.parent?.tasks?.named(" spotlessMisc" )
342+ if (generateLicenseReportEnabled.get()) {
343+ parentSpotlessMiscTask?.configure {
344+ dependsOn(generateLicenseReportTask)
345+ }
337346 }
338347
339348 // Because we reconfigure publishing to only include the shadow jar, the Gradle metadata is not correct.
@@ -390,7 +399,7 @@ project.afterEvaluate {
390399}
391400
392401licenseReport {
393- outputDir = rootProject.file (" licenses" ).absolutePath
402+ outputDir = rootProject.layout.projectDirectory.dir (" licenses" ).asFile .absolutePath
394403
395404 renderers = arrayOf(InventoryMarkdownReportRenderer ())
396405
0 commit comments