Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

kremi151
Copy link

@kremi151 kremi151 commented Aug 1, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant