nebula-plugins / gradle-lint-plugin

A pluggable and configurable linter tool for identifying and reporting on patterns of misuse or deprecations in Gradle scripts.
Apache License 2.0
771 stars 89 forks source link

Tasks created when not used #264

Closed slowr closed 5 years ago

slowr commented 5 years ago

Running gradle help for a big project, nebula.lint plugin creates 3 tasks per project even though we don't use them (generateGradleLintReport, compileJava, compileTestJava, etc). This has an impact on configuration time when you run gradle.

For more information take a look on gradle's task configuration avoidance documentation.

For example for me it creates 1082 tasks when running gradle help: image

I can look into this and create a PR that will register these tasks and not create them if it is not necessary.

rpalcolea commented 5 years ago

Hi @slowr ,

Thanks for bringing this to our attention. We will take a look on the lint side of things. We configure some task to always run so we would like registering in some cases only.

With that said, the fact that you have compileJava, compileTestJava should be on your project or other plugin. Lint does not register does tasks.

Take this multi module setup as example: https://github.com/rpalcolea/lint-multiproject-sample

other-thing module does not apply java plugin. If you look at the tasks, you won't see compileJava at all

❯ ./gradlew :other-thing:tasks --all

> Task :other-thing:tasks

------------------------------------------------------------
Tasks runnable from project :other-thing
------------------------------------------------------------

Help tasks
----------
buildEnvironment - Displays all buildscript dependencies declared in project ':other-thing'.
components - Displays the components produced by project ':other-thing'. [incubating]
dependencies - Displays all dependencies declared in project ':other-thing'.
dependencyInsight - Displays the insight into a specific dependency in project ':other-thing'.
dependentComponents - Displays the dependent components of components in project ':other-thing'. [incubating]
help - Displays a help message.
model - Displays the configuration model of project ':other-thing'. [incubating]
projects - Displays the sub-projects of project ':other-thing'.
properties - Displays the properties of project ':other-thing'.
tasks - Displays the tasks runnable from project ':other-thing'.

Other tasks
-----------
prepareKotlinBuildScriptModel
printMessage

BUILD SUCCESSFUL in 443ms
2 actionable tasks: 2 executed

while gretting-library will have it

❯ ./gradlew :greeting-library:tasks --all

> Task :greeting-library:tasks

------------------------------------------------------------
Tasks runnable from project :greeting-library
------------------------------------------------------------

Build tasks
-----------
assemble - Assembles the outputs of this project.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
classes - Assembles main classes.
clean - Deletes the build directory.
jar - Assembles a jar archive containing the main classes.
testClasses - Assembles test classes.

Documentation tasks
-------------------
groovydoc - Generates Groovydoc API documentation for the main source code.
javadoc - Generates Javadoc API documentation for the main source code.

Help tasks
----------
buildEnvironment - Displays all buildscript dependencies declared in project ':greeting-library'.
components - Displays the components produced by project ':greeting-library'. [incubating]
dependencies - Displays all dependencies declared in project ':greeting-library'.
dependencyInsight - Displays the insight into a specific dependency in project ':greeting-library'.
dependentComponents - Displays the dependent components of components in project ':greeting-library'. [incubating]
help - Displays a help message.
model - Displays the configuration model of project ':greeting-library'. [incubating]
projects - Displays the sub-projects of project ':greeting-library'.
properties - Displays the properties of project ':greeting-library'.
tasks - Displays the tasks runnable from project ':greeting-library'.

Verification tasks
------------------
check - Runs all checks.
test - Runs the unit tests.

Other tasks
-----------
compileGroovy - Compiles the main Groovy source.
compileJava - Compiles main Java source.
compileTestGroovy - Compiles the test Groovy source.
compileTestJava - Compiles test Java source.
prepareKotlinBuildScriptModel
printMessage
processResources - Processes main resources.
processTestResources - Processes test resources.

I'd suggest to look at your build and see if you don't apply java plugin to all subprojects by default. In that case, I believe gradle creates the tasks always

rpalcolea commented 5 years ago

V16.0.0 contains https://github.com/nebula-plugins/gradle-lint-plugin/pull/265

slowr commented 5 years ago

The build scan says in detail which tasks are created from which plugin and nebula.lint is the one to blame. If you call functions like getByName or getByPath this creates the task and the correct way is to use TaskProvider<Task>'s named function instead.

root project: image

sub-project: image

rpalcolea commented 5 years ago

16.0.1 has a change for that https://github.com/nebula-plugins/gradle-lint-plugin/pull/267

You should be good now

slowr commented 5 years ago

@rpalcolea seems that you missed one thing :D

in GradleLintPluginTaskConfigurer.java:52

project.tasks.withType(AbstractCompile) { abstractCompileTask ->

should be

project.tasks.withType(AbstractCompile).configureEach { abstractCompileTask ->

and then the tasks are only 1 which is the autoLint! Thanks a lot for the fast responds.

rpalcolea commented 5 years ago

ha! good catch, pushing out 16.0.2. Should be out soon!

rpalcolea commented 5 years ago

Seeing some

 > Could not create task ':compileJava'.
    |         > DefaultTaskContainer#NamedDomainObjectProvider.configure(Action) on task set cannot be executed in the current context.
    |       

with the change https://github.com/nebula-plugins/gradle-lint-plugin/pull/268 will take a look at it on Monday

rpalcolea commented 5 years ago

alright v16.0.2 is out now with the change @slowr https://github.com/nebula-plugins/gradle-lint-plugin/pull/268

can you give it a whirl?

slowr commented 5 years ago

Yes now it works correctly and only creates the autolint task! :tada: Thanks a lot for the fast solution :)