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

Allow configuration of when to run spotless in gradle build #27

Closed
simschla opened this issue Jun 6, 2016 · 8 comments
Closed

Allow configuration of when to run spotless in gradle build #27

simschla opened this issue Jun 6, 2016 · 8 comments

Comments

@simschla
Copy link
Contributor

simschla commented Jun 6, 2016

Currently spotless adds itself automatically to the gradle checkTask.

// Add our check task as a dependency on the global check task
// getTasks() returns a "live" collection, so this works even if the
// task doesn't exist at the time this call is made
project.getTasks()
    .matching(task -> task.getName().equals(JavaBasePlugin.CHECK_TASK_NAME))
    .all(task -> task.dependsOn(rootCheckTask));

We would like to be able to decide when to actually run the spotless task or even be able to only run it when directly invoked from the command line like gradlew spotless

e.g. for configuration

spotless {
    ...
}
// new
taskX.dependsOn spotless
@nedtwigg
Copy link
Member

nedtwigg commented Jun 6, 2016

If you'd like to remove spotlessCheck from the check task, this will do it:

afterEvaluate {
    tasks.getByName('check').dependsOn.remove(tasks.getByName('spotlessCheck'))
}

We're going to keep the default behavior of adding spotlessCheck to check automatically. A positive value in the gradle ecosystem is "convention over configuration" - when you add unit tests, style checkers, static analysis tools, they all hook into check by default, so that you don't have to do the plumbing yourself. Perfectly valid that you'd like to use it a different way though :)

@nedtwigg nedtwigg closed this as completed Jun 6, 2016
@simschla
Copy link
Contributor Author

simschla commented Jun 6, 2016

Thanks for the workaround, good enough for our case. 👍
Maybe adding this to the Readme.md would help other people too.

@nedtwigg
Copy link
Member

nedtwigg commented Jun 6, 2016

Maybe adding this to the Readme.md would help other people too.

It's a good question, and GitHub's issue search is very good. Hopefully others who have this same issue will find this question.

I try to make the readme describe the project as concisely as possible. I believe this use case is a less <10% case, and thus doesn't earn a spot. As evidence, if your use case was more common, then every stylechecker / static analyzer / unit test runner in the gradle ecosystem should have this in their readme.

@nedtwigg
Copy link
Member

nedtwigg commented Jun 6, 2016

Also, out of curiosity, why do you not want spotlessCheck to run on every call to check?

@simschla
Copy link
Contributor Author

simschla commented Jun 6, 2016

We like to separate concerns in the build on CI
e.g. compiling/packaging <-> running unit tests <-> running integration tests <-> auditing code.

Also, we like to keep the build as fast as possible during development to achieve small turnaround times.

@nedtwigg
Copy link
Member

nedtwigg commented Jun 6, 2016

Here's gradle's task dependency graph:

image

If you'd like to just compile and package, run assemble. If you just want to run tests, run test (or integTest if you've made a separate unit test task).

The objective of the check task is (according to the gradle docs):

All verification tasks in the project, including test. Some plugins add additional verification tasks to the project.

You can use Gradle however you'd like, but it sounds like you're swimming upstream :) If you want people to always be able to run gradle build and have it be fast, I'd recommend that you instead print out the task graph above and leave it on their desk, and then they'll know which tasks to run for themselves, depending on how fast they'd like their result.

Also, spotless is much faster than a reasonable unit test suite :)

@simschla
Copy link
Contributor Author

simschla commented Jun 6, 2016

as a matter of fact you are totally right both in "when the task is called" and in the statement that spotless is much faster ;-)

@kirici
Copy link

kirici commented Aug 25, 2023

For anyone else stumbling upon this from Google: this has been added in the meantime.
To remove spotlessCheck as a dependency to check when using the gradle plugin, add

spotless {
    isEnforceCheck = false
}

See the plugin-gradle/README.md

Background

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

No branches or pull requests

3 participants