SirOphis / jscheduler

jscheduler 🗓️ - Your go-to solution for efficient scheduling, note-taking, and task management. This open-source project offers a user-friendly web-based platform to help you organize your life and work seamlessly.
MIT License
4 stars 0 forks source link

Task: Google Java Format #3

Open Miishri opened 1 year ago

Miishri commented 1 year ago

The Google Java Format is the default format for the project. I will be adding the spotify format plugin that uses google java format under the hood to format.

Maven dependency

<dependency>
    <groupId>com.spotify.fmt</groupId>
    <artifactId>fmt-maven-plugin</artifactId>
    <version>2.21.1</version>
</dependency>

Use case for pom.xml

<properties>
    <fmt-format.version>2.21.1</fmt-format.version>
</properties>

    <build>
        <plugins>
            <plugin>
                <groupId>com.spotify.fmt</groupId>
                <artifactId>fmt-maven-plugin</artifactId>
                <version>${fmt-format.version}</version>
                <executions>
                    <execution>
                         <id>google-java-format</id>
                        <goals>
                            <goal>format</goal>
                        </goals>
                        <phase>validate</phase>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

Required run case mvn validate

Miishri commented 1 year ago

Would it be better to use the plugin provided by Intellij?

SirOphis commented 1 year ago

I think you should configure the plugin ( add it to the pom.xml) and run it as a goal :

<goals>
                        <goal>format</goal>
</goals>

then you can execute the command mvn fmt:format

SirOphis commented 1 year ago

here is an example on how to implement it:

<properties>
    <fmt-maven-plugin.version>last version here</fmt-maven-plugin.version>
</properties>

<build>
    <plugins>
        <plugin>
            <groupId>com.coveo</groupId>
            <artifactId>fmt-maven-plugin</artifactId>
            <version>${fmt-maven-plugin.version}</version>
            <executions>
                <execution>
                    <id>google-format</id>
                    <goals>
                        <goal>format</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
Miishri commented 1 year ago
<configurations>
    <alias>format</alias>
</configurations>

Would it be possible to have alias instead of using the full groupId to run format command?

SirOphis commented 1 year ago

The fmt-maven-plugin does not directly support configuring an alias for its goals. The configuration is not a valid configuration for the fmt-maven-plugin. you can use the Maven build-helper-maven-plugin to create an alias for the goals.

Miishri commented 1 year ago

I have used the format and it works on validation for mvn validate. Please check it as I cannot find the pom.xml and unsure where to test in the task branch I have created.

Miishri commented 1 year ago

After doing some digging, I have sound the old pom.xml that you were using. Should I copy that and use it in my branch just for the sake of testing? Is there any other way you want me to through with this?

https://github.com/SirOphis/jscheduler/commit/fee622ac1c4786c1608154c4f46f30ec543f3cbe?short_path=e0cd712#diff-e0cd71223ea366733ef4996911891caf5f2b1668a138df8661b557fcc5069bb1

Could I also use maven-invoker-plugin to create automated tests instead of manual testing?

SirOphis commented 1 year ago

Hello, create a separated issue for maven-invoker-plugin. also i will add a new pom.xml and a project structure in the main branch you just have to rebase it on top of your branch then test and commit everything.

Miishri commented 12 months ago

Hey,

I saw your recent commit for the project and I am confused about the files. Why is there a mvn wrapper inside the back folder as well as the jscheduler folder?

Miishri commented 12 months ago
[INFO] Scanning for projects...
[INFO] 
[INFO] ---------------------< com.jscheduler:jscheduler >----------------------
[INFO] Building jscheduler 0.0.1-SNAPSHOT
[INFO]   from pom.xml
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] --- fmt:2.21.1:format (google-java-format) @ jscheduler ---
[INFO] Skipping format check: project uses 'pom' packaging
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.736 s
[INFO] Finished at: 2023-11-20T08:58:48+01:00
[INFO] ------------------------------------------------------------------------
[WARNING] 
[WARNING] Plugin validation issues were detected in 1 plugin(s)
[WARNING] 
[WARNING]  * com.spotify.fmt:fmt-maven-plugin:2.21.1
[WARNING] 
[WARNING] For more or less details, use 'maven.plugin.validation' property with one of the values (case insensitive): [BRIEF, DEFAULT, VERBOSE]
[WARNING] 
Miishri commented 12 months ago

I have tried running the plugin and it causes these issues? Could I get any insights on how to ensure it doesn't skip the format check due to pom packaging?

SirOphis commented 12 months ago

Hello, "I saw your recent commit for the project and I am confused about the files. Why is there a mvn wrapper inside the back folder as well as the jscheduler folder?" -> we are implementing a modular approach for each microservice, we have a parent folder "back" that has a general pom.xml packaged as pom that will server for common dependencies between all modules such as "lombok" "spring boot starter" etc and each module has his own pom.xml that inherit all of those common dependencies etc.

-> to apply the google formatter plugin to all submodules, you can configure it in the section of the parent pom.xml and make sure to include the configuration within the section under

Miishri commented 12 months ago

I'm confused regarding which one is the parent pom? If it's the one in Jscheduler folder then why does it have relative path? Isn't that only to link children pom xmls to inherit from? Please correct me if I'm wrong, I'll continue by adding the parent pom path to the child pom xmls relative paths.

SirOphis commented 12 months ago

regarding your question: Parent POM (jscheduler/pom.xml): This POM should have pom to indicate that it's a parent POM. and it should have a tag inside of it we should add the artifcat of our module

example :

<project>
 <!-- specifying the packaging pom so it is a parent for our submodules -->
    <packaging>pom</packaging>

    <!-- Add Spring Boot parent -->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.1.5</version>
    </parent>

    <!-- Other configurations and dependencies as needed -->

    <modules>
        <module>submodule</module>
        <!-- Add other modules as needed -->
    </modules>
</project>

In our submodules (forexample : usermodule) the pom should have a parent section for example:

<parent>
        <groupId>com.jscheduler</groupId>
        <artifactId>jscheduler</artifactId>
        <version>0.0.1-SNAPSHOT</version>
         <relativePath>../pom.xml</relativePath> <!--we should specify the path to our parent pom-->
</parent>

and the artifactId with the name of the submodule that will be also precised in the parent pom.xml in tag

<artifactId>submodule</artifactId>

about the relative path in our parent pom.xml we can omit it i hope it is clear now !