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

Add 'may-spotless-apply' profile #1017

Merged
merged 2 commits into from
Sep 24, 2024
Merged

Conversation

Vlatombe
Copy link
Member

@Vlatombe Vlatombe commented Sep 23, 2024

I often find myself forgetting to apply spotless before committing.

On some repositories, I have set up a pre-commit git hook running mvn spotless:check. However, this has to be set up on each repository that has spotless check enabled, and disabled on those which don't.

I think this goes one step further, by defining a conventional maven profile may-spotless-apply that will run spotless:apply only if spotless is enabled for the given repository.

This allows any user to incorporate -Pmay-spotless-apply as part of their usual build command (or defined in their maven settings active profiles section), and have spotless:apply automatically called if the project has it enabled.

Example Maven settings.xml

<settings>
  [...]
  <activeProfiles>
    [...]
    <activeProfile>may-spotless-apply</activeProfile>
  </activeProfiles>
</settings>

See also jenkinsci/pom#611

Testing done

Submitter checklist

  • Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
  • Ensure that the pull request title represents the desired changelog entry
  • Please describe what you did
  • Link to relevant issues in GitHub or Jira
  • Link to relevant pull requests, esp. upstream and downstream changes
  • Ensure you have provided tests - that demonstrates feature works or fixes the issue

I often find myself forgetting to apply spotless before committing.

On some repositories, I have set up a pre-commit git hook running `mvn
spotless:check`. However, this has to be set up on each repository that
has spotless check enabled, and disabled on those which don't.

I think this goes one step further, by defining a conventional maven
profile `may-spotless-apply` that will run `spotless:apply` *only* if
spotless is enabled for the given repository.

This allows any user to incorporate `-Pmay-spotless-apply` as part of
their usual build command (or defined in their maven settings active profiles section),
and have `spotless:apply` automatically called if the project has it enabled.
Copy link
Member

@jglick jglick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defined in their maven settings active profiles section

What would this look like? If you just set

        <profile>
            <id>may-spotless-apply</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>

(with no further configuration in ~/.m2/settings.xml) does that in fact cause the config in this parent POM to be run?

</goals>
<phase>validate</phase>
<configuration>
<skip>${spotless.check.skip}</skip>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plugin-pom/pom.xml

Lines 126 to 127 in 64885a6

<!-- Set to false to enable Spotless -->
<spotless.check.skip>true</spotless.check.skip>
FTR

@Vlatombe
Copy link
Member Author

In fact, Maven settings.xml has a specific section for profiles you want to activate unconditionally.

<settings>
  [...]
  <activeProfiles>
    [...]
    <activeProfile>may-spotless-apply</activeProfile>
  </activeProfiles>
</settings>

@jglick
Copy link
Member

jglick commented Sep 23, 2024

Copy link
Member

@timja timja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you document it please

@Vlatombe Vlatombe requested a review from timja September 24, 2024 06:47
Copy link
Member

@basil basil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

@basil basil merged commit bd5687b into jenkinsci:master Sep 24, 2024
2 checks passed
@Vlatombe Vlatombe deleted the may-spotless-apply branch October 11, 2024 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants