hierynomus / license-gradle-plugin

Manage your license(s)
http://www.javadude.nl
Other
406 stars 114 forks source link

Make use of Gradle Task Configuration Avoidance for registering tasks #210

Open kremi151 opened 2 years ago

kremi151 commented 2 years ago

This PR improves the plugin by registering tasks using Task Configuration Avoidance.

In a nutshell, the changes will register the Gradle tasks, but they will only be configured if they are actually required (i.e. when they will actually be executed), improving the time Gradle takes to configure everything.

I noticed that the plugin was configuring downloadLicenses, license and licenseFormat tasks even if a small Gradle task was run.

For demo purposes, I created a small demo project, which defines three modules, each having a simple helloWorld task whose only purpose is to print something to the console: LicenseGradlePluginLazyTaskConfigurationSample.zip

The project prints the tasks that are configured by Gradle to the console.

When running ./gradlew :module1:helloWorld with the latest released plugin version, the console output looks as follows:

$ ./gradlew :module1:helloWorld

Configure project : TASK CONFIGURED: :downloadLicenses TASK CONFIGURED: :license TASK CONFIGURED: :licenseFormat TASK CONFIGURED: :module1:downloadLicenses TASK CONFIGURED: :module1:license TASK CONFIGURED: :module1:licenseFormat TASK CONFIGURED: :module2:downloadLicenses TASK CONFIGURED: :module2:license TASK CONFIGURED: :module2:licenseFormat TASK CONFIGURED: :module3:downloadLicenses TASK CONFIGURED: :module3:license TASK CONFIGURED: :module3:licenseFormat

Configure project :module1 TASK CONFIGURED: :module1:check TASK CONFIGURED: :module1:licenseMain TASK CONFIGURED: :module1:licenseFormatMain TASK CONFIGURED: :module1:licenseTest TASK CONFIGURED: :module1:licenseFormatTest

Configure project :module2 TASK CONFIGURED: :module2:check TASK CONFIGURED: :module2:licenseMain TASK CONFIGURED: :module2:licenseFormatMain TASK CONFIGURED: :module2:licenseTest TASK CONFIGURED: :module2:licenseFormatTest

Configure project :module3 TASK CONFIGURED: :module3:check TASK CONFIGURED: :module3:licenseMain TASK CONFIGURED: :module3:licenseFormatMain TASK CONFIGURED: :module3:licenseTest TASK CONFIGURED: :module3:licenseFormatTest TASK CONFIGURED: :module1:helloWorld

Task :module1:helloWorld Hello from module1

BUILD SUCCESSFUL in 589ms 1 actionable task: 1 executed

As you can see, downloadLicenses, license and licenseFormat tasks are configured even if they are not run, also for modules that are not affected by the current Gradle run.

After my changes, the output looks as follows:

$ ./gradlew :module1:helloWorld TASK CONFIGURED: :module1:helloWorld

Task :module1:helloWorld Hello from module1

BUILD SUCCESSFUL in 475ms 1 actionable task: 1 executed