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

Unfortunate automated execution in Eclipse via m2e #1814

Closed
taftster opened this issue Sep 14, 2023 · 3 comments · Fixed by #2059
Closed

Unfortunate automated execution in Eclipse via m2e #1814

taftster opened this issue Sep 14, 2023 · 3 comments · Fixed by #2059

Comments

@taftster
Copy link

I wanted to bring up what I generally believe to be an unfortunate misconfiguration of the m2e lifecycle mapping recently added as part of #1413 released as plugin-maven-2.29.0

While I believe adding m2e support is probably a good idea, the lifecycle-mapping-metadata.xml [1] specifies "runOnIncremental" to be 'true'. This is frustrating while working inside of Eclipse, as any save to a source file instantly causes a reformatting of the source, which is definitely not expected behavior.

The jarring experience here is that often, while you're "thinking" or in the middle of development, you don't necessarily want your source code to be reformatted unexpectedly just by merely saving the file. You might not consider the code as "complete" yet and want to leave your current formatting in place. With spotless configured to run on save, it's often the case that the newly formatted code is not as readable as what the developer is currently expressing while in the development mode.

Even for example creating a new empty class in the project, the source code is immediately reformatted which often results in the closing of the empty curly braces (if using the google format plugin). That is, the plugin is being executed even when a source file has not yet even been saved, making the class difficult to immediately type code into as the cursor focus is lost!

If not specified, the m2e project assumes the default of runOnIncremental to be 'false', which would be a much more reasonable setting for the lifecycle mapping. Or setting the action to "ignore" would prevent the plugin from executing inside of the Eclipse lifecycle entirely.

In general, while I appreciate having the "opinionated" source formatting being performed on my code during the traditional maven lifecycle (I bind spotless to my verify phase), having it executed for every save in the IDE is overkill and disruptive to productivity. A developer should be able to edit their source in whatever format they desire while developing and then coerce the formatting as a last step after the session is complete.

I would be more than happy to provide a PR that reduces the execution behavior of the plugin as described above. I'd personally prefer if the plugin was set to the "ignore" action. But at minimum, runOnIncremental should likely be changed to the default value of 'false' which would at least help with this issue.

Thanks.

[1] https://github.com/diffplug/spotless/blob/main/plugin-maven/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml

@taftster
Copy link
Author

taftster commented Sep 18, 2023

As a work-around to the described behavior, the following snippet can be added to the pom (project or parent) to help inform the m2e plugin to ignore the spotless plugin. Note this MUST go into the pluginManagement section of the pom.

<pluginManagement>
  <plugin>
    <groupId>org.eclipse.m2e</groupId>
    <artifactId>lifecycle-mapping</artifactId>
    <version>1.0.0</version>
    <configuration>
      <lifecycleMappingMetadata>
        <pluginExecutions>
          <pluginExecution>
            <pluginExecutionFilter>
              <groupId>com.diffplug.spotless</groupId>
              <artifactId>spotless-maven-plugin</artifactId>
              <versionRange>[2.29.0,)</versionRange>
              <goals>
                <goal>apply</goal>
                <goal>check</goal>
              </goals>
            </pluginExecutionFilter>
            <action>
              <ignore/>
            </action>
          </pluginExecution>
        </pluginExecutions>
      </lifecycleMappingMetadata>
    </configuration>
  </plugin>
</pluginManagement>

@nedtwigg
Copy link
Member

nedtwigg commented Dec 4, 2023

A PR that improves your situation would be welcome. @kwin feel free to chime in if you have an opinion.

@kwin
Copy link
Contributor

kwin commented Dec 4, 2023

kwin added a commit to kwin/spotless that referenced this issue Mar 2, 2024
Clear stale messages during "check" mojo
Allow to parameterize message severity
Add Spotless prefix to messages

This closes diffplug#1814
This closes diffplug#2037
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants