I think reformatting files during every build is less desirable and adds
risk.  I prefer the build to *enforce* the desired results, failing as
needed, and configuring the IDEs to auto-format the files on save.  Both
Eclipse and IntelliJ have many configurable "save actions" for file format
and cleanup options (e.g. organize imports, remove unused imports, remove
trailing spaces, add 'final' where possible, convert loops, etc.).

This approach formats files earliest possible (at save time), the developer
sees the formatting before commit, prevents the build from changing
non-generated source files (risk), eliminates a build step, and eliminates
a "new commit of non-developer changed files" issue.

The challenge is still everyone using the same formatter settings and
everyone configuring "save actions"...  Improving the "code style enforcing
rules" (e.g. Checkstyle) and failing the build will "encourage" developers
to setup their IDE well for this.


On Thu, Oct 13, 2022 at 5:50 AM Olivier Lamy <ol...@apache.org> wrote:

> On Thu, 13 Oct 2022 at 17:47, Tamás Cservenák <ta...@cservenak.net> wrote:
> >
> > Howdy,
> >
> > to not get lost in implementation details, it is really unimportant
> > (spotless, this or that...)
> >
> > What IS important is that we agree to implement "IDE agnostic source
> > formatting", that happens during build
> > (by maven plugin). This means _everyone_ will end up with 100% the same
> > result.
> >
> > The only thing that comes to my mind is "sloppy committer" who does not
> > build but pushes....
>
> not sure to understand. You mean formatting sources will be bind to a
> phase and be executed automatically?
>
> Wouldn’t it be better to still have a check as today (checkstyle:check
> or the used foo-bar-formatter-plugin:check) which checks the sources
> at validate phase.
> Then in case of failure, the committer can just run
> foo-bar-formatted-plugin:format.
> So committer can apply some manual changes as well.
> this will detect "sloppy" committer as today by simply failing without
> adding another plugin running some scm command during the build.
>
> > Is there some option to have a profile (activated on CI) that detects
> there
> > are "uncommitted changes" post build?
> > As that would mean that sourcetree contains sources NOT formatted, and
> that
> > CI build did reformat them...
> >
> > But even without this step mitigation is simple: someone just rebuilds
> HEAD
> > and commits...
> >
> > Thanks
> > T
> >
> > On Thu, Oct 13, 2022 at 8:41 AM Tamás Cservenák <ta...@cservenak.net>
> wrote:
> >
> > > Formatting happens during build, so once merged all we need is to merge
> > > master into PR branches...
> > >
> > > T
> > >
> > > On Thu, Oct 13, 2022 at 8:40 AM Sylwester Lachiewicz <
> > > slachiew...@gmail.com> wrote:
> > >
> > >> What about already open PR with some features or bug fixes.
> > >> Don't we should review and merge it before reformatting code -
> otherwise
> > >> we
> > >> will have lots of merge conflicts and over time no one will have
> energy to
> > >> review it?
> > >>
> > >> Sylwester
> > >>
> > >> śr., 12 paź 2022, 18:23 użytkownik Guillaume Nodet <gno...@apache.org
> >
> > >> napisał:
> > >>
> > >> > I'd like to propose merging the following PRs:
> > >> >  * https://github.com/apache/maven-shared-resources/pull/1
> > >> >  * https://github.com/apache/maven-site/pull/329
> > >> >  * https://github.com/apache/maven/pull/824
> > >> >  * https://github.com/apache/maven-resolver/pull/147
> > >> > ... and more to come
> > >> >
> > >> > The idea is to use plugins to automatically reformat the source
> code and
> > >> > sort imports to obey the maven coding style.
> > >> > The first PR adds the necessary resources to maven-shared-resources
> : a
> > >> new
> > >> > header file, as there's a requirement to put the header at the very
> > >> > beginning for the import sorter plugin to work correctly (else it
> > >> considers
> > >> > the license comment to be part of comment headers and screws the
> > >> > formatting), and the eclipse xml formatter plugin.
> > >> > The second PR updates the web site to point to that file which
> would be
> > >> in
> > >> > git instead of on the maven web site, and also updates the
> instruction
> > >> for
> > >> > IDEA since it has been supporting the eclipse xml config for years
> now).
> > >> > The third and fourth PRs are updates on maven and maven-resolver to
> > >> apply
> > >> > those two plugins.
> > >> >
> > >> > Those plugins have been used on mvnd and maven-build-cache-extension
> > >> > already, although they are not using a single shared resource that
> > >> would be
> > >> > added by the first PR.  Hence mvnd is still using its previous
> coding
> > >> > style.
> > >> >
> > >> > Another point is that those plugins are fast and only do not process
> > >> files
> > >> > if they have been already processed and untouched since the last
> > >> build.  So
> > >> > from a daily development pov, this is transparent and does not
> incur any
> > >> > additional processing time during the build (or not much really).
> > >> >
> > >> > Cheers,
> > >> > Guillaume
> > >> >
> > >>
> > >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscr...@maven.apache.org
> For additional commands, e-mail: dev-h...@maven.apache.org
>
>

Reply via email to