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 options to skip Maven goals from command line #360

Closed
lfvjimisola opened this issue Feb 13, 2023 · 7 comments
Closed

Add options to skip Maven goals from command line #360

lfvjimisola opened this issue Feb 13, 2023 · 7 comments
Assignees
Milestone

Comments

@lfvjimisola
Copy link

lfvjimisola commented Feb 13, 2023

We would like to default to always applying formatting rules and then validating, i.e.

    <build>
        <plugins>
            <plugin>
                <groupId>io.spring.javaformat</groupId>
                <artifactId>spring-javaformat-maven-plugin</artifactId>
                <version>0.0.35</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <inherited>true</inherited>
                        <goals>
                            <goal>apply</goal>
                            <goal>validate</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

However, in our pipelines we then need to skip the apply goal to make sure that the code is actually correctly validated.

We would like to avoid using profiles and just add command line parameter similar to -Dmaven.test.skip, e.g.

  • -Dspring-javaformat.apply.skip
  • -Dspring-javaformat.validate.skip

I've checked issues and code and could not see that it has been brought up or is implemented.

@philwebb philwebb added this to the 0.0.x milestone Feb 13, 2023
@jimisola
Copy link

jimisola commented Feb 13, 2023

This should be relatively easy to implement. Something similar to https://github.com/spring-projects/spring-boot/blob/7377d85096ed943a06341d94e43a1208238850b5/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/StopMojo.java#L67-L68

Yes, exactly. Or as here ;):

https://github.com/spring-io/spring-javaformat/blob/main/spring-javaformat-maven/spring-javaformat-maven-plugin/src/main/java/io/spring/format/maven/ValidateMojo.java#L43

I missed that there is a skip in ValidateMojo ("spring-javaformat.skip). A bit unfortunate that is using a common property name.

I would have preferred to use spring-javaformat.skip to skip both validate and apply goals. Changing it now would be a breaking change.

Perhaps, adding:

  • spring-javaformat.apply.skip: skip apply goal
  • spring-javaformat.validate.skip: skip validate goal

and deprecating:

  • spring-javaformat.skip: to allow to change it's behavior or using spring-javaformat.all.skip

The "skip all" could be placed directly in FormatMojo or?

@philwebb philwebb modified the milestones: 0.0.x, 0.0.36 Feb 17, 2023
@philwebb philwebb self-assigned this Feb 17, 2023
@lfvjimisola
Copy link
Author

That was fast. Thanks @philwebb

@lfvjimisola
Copy link
Author

@philwebb Are there any tests for this? I can't seem to get it work unless I'm making a silly mistake.
Can you please confirm on your end?

@lfvjimisola
Copy link
Author

MRE: test.zip

u30576@DCL0004:~/test/test$mvn validate -Dspring-javaformat.apply.skip=true
[INFO] Scanning for projects...
[INFO] 
[INFO] -----------------------------< test:test >------------------------------
[INFO] Building test 0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- spring-javaformat-maven-plugin:0.0.38:apply (default) @ test ---
[INFO] 
[INFO] --- spring-javaformat-maven-plugin:0.0.38:validate (default) @ test ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.280 s
[INFO] Finished at: 2023-02-23T09:46:23+01:00
[INFO] ------------------------------------------------------------------------

@wilkinsona
Copy link
Contributor

wilkinsona commented Feb 23, 2023

@lfvjimisola It's a mismatch between the code and the readme. -Dspring-javaformat.format.skip=true will work. I've opened #365. I'll have a chat with @philwebb and decide if we want to update the code or the README.

@lfvjimisola

This comment was marked as duplicate.

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

No branches or pull requests

4 participants