Skip to content

Commit

Permalink
Fix license report task in multi-project setups (#191)
Browse files Browse the repository at this point in the history
* Fix license report task in multi-project setups

Currently running the license report task in multi-project setups is frequently causing the task to fail with "FWK005 parse may not be called while parsing." This is caused by the fact that LicenseReportTask.kt uses a static (companion) parser object. If parsing is already in progress for one project, a second report task on another project will fail if it tries to parse at the same time. This can be resolved by using an instance local parser variable.

* Add reasoning to use non-static parser in license task

Ensure the issue is not re-introduced in the future, since it would be difficult to cover this with an actual test due to the race condition nature of the issue.

* Fix comment formatting with ktlintFormat

Co-authored-by: Florian Link <[email protected]>
  • Loading branch information
fllink and Florian Link authored Apr 19, 2022
1 parent dd361a0 commit 785cbe7
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ internal open class LicenseReportTask : BaseLicenseReportTask() { // tasks can't
private var pomConfiguration = "poms"
private var tempPomConfiguration = "tempPoms"

/**
* Use a non-static parser instance to avoid errors with concurrent licenseReport tasks
* in multi-project setups. See https://github.com/jaredsburrows/gradle-license-plugin/pull/191
* for additional details.
*/
private var xmlParser = XmlParser(false, false)

@TaskAction fun licenseReport() {
setupEnvironment()
initDependencies()
Expand Down Expand Up @@ -501,7 +508,6 @@ internal open class LicenseReportTask : BaseLicenseReportTask() { // tasks can't
}

internal companion object {
private val xmlParser = XmlParser(false, false)
private const val ANDROID_SUPPORT_GROUP_ID = "com.android.support"
private const val APACHE_LICENSE_NAME = "The Apache Software License"
private const val APACHE_LICENSE_URL = "http://www.apache.org/licenses/LICENSE-2.0.txt"
Expand Down

0 comments on commit 785cbe7

Please sign in to comment.