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

Duplicate clean task #521

Closed
AllanWang opened this issue Feb 4, 2020 · 4 comments
Closed

Duplicate clean task #521

AllanWang opened this issue Feb 4, 2020 · 4 comments
Labels

Comments

@AllanWang
Copy link

As of spotless 3.27.0, it seems like a clean task is created. I'm not sure about now, but at least a year ago, all new projects had a clean task created by the IDE by default:

task clean(type: Delete) {
    delete rootProject.buildDir
}

The fix for us is to remove the inline clean task.

If this is expected, consider adding this in the changelog. If this is not expected, can we avoid the naming conflict somehow?

@nedtwigg
Copy link
Member

nedtwigg commented Feb 4, 2020

This is where we "create" the clean task:

// make sure there's a `clean` task
project.getPlugins().apply(BasePlugin.class);
// setup the extension
spotlessExtension = project.getExtensions().create(SpotlessExtension.EXTENSION, SpotlessExtension.class, project);
// clear spotless' cache when the user does a clean
Task clean = project.getTasks().getByName(BasePlugin.CLEAN_TASK_NAME);

I think the way we're doing it now is the conventional way which plays nice with other plugins. I think it would look like this for your example

apply plugin: BasePlugin
tasks.getByName(BasePlugin.CLEAN_TASK_NAME).doLast {
    delete rootProject.buildDir
}

@AllanWang
Copy link
Author

Can this be better documented? I'm fine with it, but it basically creates an error for any project that kept the default template until a change is made

@nedtwigg
Copy link
Member

nedtwigg commented Feb 4, 2020

A quick git blame shows that the line I linked to above is at least 2 years old, and it looks like BasePlugin has worked this way since Gradle 2.0. In my faulty memory, this is the way that I've always created or hooked the clean task in plugins and buildscripts, so I don't remember a change, and I try to be thorough in the changelog. I'm happy to merge a PR which updates the documentation or changelog to help others in your situation. Having this issue in the search will be helpful to others who have that same IDE template too, so you've already provided a service to the project even if you don't have time for a PR :)

@nedtwigg
Copy link
Member

Happy to reopen if there's further action or discussion to be had.

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

No branches or pull requests

2 participants