Want to have faster builds when changing only code in main.
From commandline, wanted to know if there is any task to only clean main folder’s classes and intermediate objects (using Kotlin)
If not was considering adding a task like (project uses gradle 7.2)
Any reasons this would be a bad idea?
If we make changes to test then user has to remember to call the regular clean or hope that java picks up on changed classes.
The tasks cleanProcessResources, cleanCompileJava, and cleanCompileKotlin should together achieve the same and cleaner, so if you really need a cleanMain task you could make it a lifecycle task, meaning without own logic and just depending on those three tasks.
But the actual problem you have is, that you feel the need for such a task.
I guess you are just too used to run mvn clean package to get halfway reliable and correct results.
In Gradle world this is just a very bad habit.
By always doing ./gradlew clean build or so, you completely destroy one of the biggest strengths of Gradle, which is avoiding unnecessary work, and thus waste a lot of your time.
You should just stop doing clean unless cleaning the project is actually what you want to do.
If cleanis necessary with a Gradle build to get correct or reliable results, then this is a bug in that build or in a plugin it uses that should be fixed instead of worked around by wasting your time.