Skip to content

Commit dde9173

Browse files
authored
Initial works to add spotless (#64)
* Initial works to add spotless * New upgrade * Tested spotless
1 parent 23cee4f commit dde9173

File tree

11 files changed

+119
-57
lines changed

11 files changed

+119
-57
lines changed

.cursor/rules/111-java-maven-deps-and-plugins.mdc

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ alwaysApply: false
77

88
This rule provides a comprehensive, conversational approach to updating Maven pom.xml files with properties, dependencies, plugins, and profiles. It MUST ask questions first to understand the project needs and then conditionally add only relevant components.
99

10+
**⚠️ CRITICAL: NO CACHING OF QUESTIONS ⚠️**
11+
- NEVER use cached or remembered questions from previous interactions
12+
- ALWAYS read the template file fresh using file_search and read_file tools
13+
- Verify all questions and options match the current template content exactly
14+
1015
## Pre-requisites Check
1116

1217
**CRITICAL**: This step MUST be completed before proceeding to any subsequent steps. Do NOT continue with Step 1 (Project Assessment Questions) until the Maven Wrapper question is fully resolved.
@@ -61,9 +66,11 @@ This rule provides a comprehensive, conversational approach to updating Maven po
6166

6267
**MANDATORY PROCESS:**
6368

64-
1. **Reference the Template**: Use the questions from [java-maven-questions-template.md](mdc:.cursor/rules/templates/java-maven-questions-template.md)
69+
1. **ALWAYS READ THE TEMPLATE FRESH**: Before asking any questions, you MUST use the `file_search` and `read_file` tools to locate and read the complete content of `java-maven-questions-template.md`. DO NOT use cached or remembered questions from previous interactions.
70+
71+
2. **Reference the Template**: Use the questions from [java-maven-questions-template.md](mdc:.cursor/rules/templates/java-maven-questions-template.md)
6572

66-
2. **STRICT ENFORCEMENT RULES:**
73+
3. **STRICT ENFORCEMENT RULES:**
6774
- ✅ Ask questions **ONE BY ONE** in the exact order specified in the template
6875
- ✅ **WAIT** for user response to each question before proceeding to the next
6976
- ✅ Use the **EXACT wording** from the template questions
@@ -73,15 +80,20 @@ This rule provides a comprehensive, conversational approach to updating Maven po
7380
- ✅ **Do NOT** assume answers or provide defaults
7481
- ✅ **Do NOT** skip questions or change their order
7582

76-
3. **QUESTION SEQUENCE** (from template):
83+
4. **QUESTION SEQUENCE** (from template - MUST BE READ FRESH EACH TIME):
7784
- **Question 1**: [Project Nature](mdc:.cursor/rules/templates/java-maven-questions-template.md#1-project-nature) (single selection from the template)
7885
- **Question 2**: [Java Version](mdc:.cursor/rules/templates/java-maven-questions-template.md#2-java-version) (single selection from the template)
7986
- **Question 3**: [Build and Quality Aspects](mdc:.cursor/rules/templates/java-maven-questions-template.md#3-build-and-quality-aspects) (multiple selection allowed from the template)
8087
- **Question 4**: [Coverage Threshold](mdc:.cursor/rules/templates/java-maven-questions-template.md#4-coverage-threshold) (conditional - only if coverage selected)
8188
- **Question 5**: [Sonar Configuration](mdc:.cursor/rules/templates/java-maven-questions-template.md#5-sonar-configuration-conditional) (conditional - only if static analysis with Sonar selected)
8289
- **Question 6**: [Sonar Host Configuration](mdc:.cursor/rules/templates/java-maven-questions-template.md#6-sonar-host-configuration-conditional) (conditional - only if Sonar configuration enabled)
8390

84-
4. **VALIDATION CHECKPOINT:**
91+
5. **TEMPLATE VERIFICATION STEP:**
92+
- Before asking questions, verify that ALL options from the template are included
93+
- Cross-check your question content against the freshly read template file
94+
- If there are discrepancies, re-read the template and correct your questions
95+
96+
6. **VALIDATION CHECKPOINT:**
8597
- **STOP** and verify all applicable questions have been answered
8698
- **Do NOT proceed** to Step 2 until complete responses received
8799
- **Confirm** understanding of user selections before implementation

.cursor/rules/templates/java-maven-plugins-template.md

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,7 @@ This template provides Maven plugin configurations that should be added conditio
66

77
## Core Plugins
88

9-
### Add maven-plugin-enforcer (Enhanced)
10-
11-
**When to use**: Always recommended for build consistency and dependency management.
12-
**User question**: "Do you want enhanced dependency validation and build enforcement? (y/n)"
13-
14-
Nature: General
15-
Category: Build
16-
17-
Update the pom.xml with this enhanced enforcer plugin:
18-
19-
```xml
20-
<plugin>
21-
<groupId>org.codehaus.mojo</groupId>
22-
<artifactId>flatten-maven-plugin</artifactId>
23-
<version>${maven-plugin-flatten.version}</version>
24-
<configuration>
25-
</configuration>
26-
<executions>
27-
<execution>
28-
<id>flatten</id>
29-
<phase>process-resources</phase>
30-
<goals>
31-
<goal>flatten</goal>
32-
</goals>
33-
</execution>
34-
<execution>
35-
<id>flatten.clean</id>
36-
<phase>clean</phase>
37-
<goals>
38-
<goal>clean</goal>
39-
</goals>
40-
</execution>
41-
</executions>
42-
</plugin>
43-
```
44-
45-
## Add maven-plugin-enforcer
9+
### Add maven-plugin-enforcer
4610

4711
Nature: General
4812
Category: Build
@@ -157,6 +121,44 @@ Update the pom.xml with this new plugin:
157121

158122
## Optional Build Enhancement Plugins
159123

124+
### Add spotless-maven-plugin
125+
126+
Nature: General
127+
Category: Build
128+
129+
Update the pom.xml with this plugin:
130+
131+
```xml
132+
<plugin>
133+
<groupId>com.diffplug.spotless</groupId>
134+
<artifactId>spotless-maven-plugin</artifactId>
135+
<version>${maven-plugin-spotless.version}</version>
136+
<configuration>
137+
<encoding>UTF-8</encoding>
138+
<java>
139+
<removeUnusedImports />
140+
<importOrder>
141+
<order>,\#</order>
142+
</importOrder>
143+
<endWithNewline />
144+
<trimTrailingWhitespace />
145+
<indent>
146+
<spaces>true</spaces>
147+
<spacesPerTab>4</spacesPerTab>
148+
</indent>
149+
</java>
150+
</configuration>
151+
<executions>
152+
<execution>
153+
<goals>
154+
<goal>check</goal>
155+
</goals>
156+
<phase>process-sources</phase>
157+
</execution>
158+
</executions>
159+
</plugin>
160+
```
161+
160162
### Add flatten-maven-plugin
161163

162164
**When to use**: For library projects that will be published to Maven repositories.

.cursor/rules/templates/java-maven-properties-template.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ Start with essential build properties that every project needs (use the Java ver
5757

5858
**Only add plugin version properties for selected features**:
5959

60+
### Static Analysis
61+
**If Format source code selected**:
62+
```xml
63+
<maven-plugin-spotless.version>2.44.5</maven-plugin-spotless.version>
64+
```
65+
6066
### Integration Testing
6167
**If Integration Testing selected**:
6268
```xml

.cursor/rules/templates/java-maven-questions-template.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Options:
2828
**What build and quality aspects are important for your project?** (Select all that apply)
2929

3030
Options:
31+
- Format source code (Spotless)
3132
- Compiler behaviour improvements with ErrorProne + NullAway (Ask for JSpecify)
3233
- Integration testing (Failsafe)
3334
- Code coverage reporting (JaCoCo)

examples/maven-demo/README-DEV.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
# Clean and package in one command
1717
./mvnw clean package
1818

19+
#Format source code
20+
./mvnw spotless:apply
21+
1922
# Run integration tests
2023
./mvnw verify
2124

examples/maven-demo/pom.xml

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,18 @@
99
<version>1.0-SNAPSHOT</version>
1010

1111
<properties>
12+
<java.version>21</java.version>
13+
<maven.version>3.9.10</maven.version>
1214
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13-
<maven.compiler.release>17</maven.compiler.release>
15+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
16+
<maven.compiler.release>${java.version}</maven.compiler.release>
1417

18+
<!-- Dependency versions -->
1519
<assertj.version>3.27.3</assertj.version>
20+
21+
<!-- Plugin versions -->
22+
<maven-plugin-spotless.version>2.44.5</maven-plugin-spotless.version>
23+
1624
</properties>
1725

1826
<dependencyManagement>
@@ -49,5 +57,35 @@
4957
</dependencies>
5058

5159
<build>
60+
<plugins>
61+
<plugin>
62+
<groupId>com.diffplug.spotless</groupId>
63+
<artifactId>spotless-maven-plugin</artifactId>
64+
<version>${maven-plugin-spotless.version}</version>
65+
<configuration>
66+
<encoding>UTF-8</encoding>
67+
<java>
68+
<removeUnusedImports />
69+
<importOrder>
70+
<order>,\#</order>
71+
</importOrder>
72+
<endWithNewline />
73+
<trimTrailingWhitespace />
74+
<indent>
75+
<spaces>true</spaces>
76+
<spacesPerTab>4</spacesPerTab>
77+
</indent>
78+
</java>
79+
</configuration>
80+
<executions>
81+
<execution>
82+
<goals>
83+
<goal>check</goal>
84+
</goals>
85+
<phase>process-sources</phase>
86+
</execution>
87+
</executions>
88+
</plugin>
89+
</plugins>
5290
</build>
5391
</project>

examples/maven-demo/src/main/java/info/jab/demo/EulerProblem01.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ public class EulerProblem01 implements IEuler<Integer, Integer> {
55
/**
66
* Multiples of 3 or 5
77
* https://projecteuler.net/problem=1
8-
*
8+
*
99
* If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3,5,6 and 9. The sum of these multiples is 23.
1010
* Find the sum of all the multiples of 3 or 5 below the provided parameter.
11-
*
11+
*
1212
* @param limit
1313
* @return
1414
*/
@@ -25,4 +25,4 @@ public Integer solution(Integer limit) {
2525

2626
return sum;
2727
}
28-
}
28+
}

examples/maven-demo/src/main/java/info/jab/demo/EulerProblem02.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ private static List<Long> fibonacci(Long limit) {
2727
/**
2828
* Even Fibonacci numbers
2929
* https://projecteuler.net/problem=2
30-
*
31-
* Each new term in the Fibonacci sequence is generated by adding the previous two terms.
30+
*
31+
* Each new term in the Fibonacci sequence is generated by adding the previous two terms.
3232
* By starting with 1 and 2, the first 10 terms will be:
3333
* 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
34-
*
35-
* By considering the terms in the Fibonacci sequence whose values do not exceed four million,
34+
*
35+
* By considering the terms in the Fibonacci sequence whose values do not exceed four million,
3636
* find the sum of the even-valued terms.
37-
*
37+
*
3838
* @param limit
3939
* @return
4040
*/

examples/maven-demo/src/test/java/info/jab/demo/EulerProblem01Test.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package info.jab.demo;
22

3-
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
4-
5-
import org.junit.jupiter.api.Test;
63
import info.jab.demo.utils.EulerAnswersLoader;
4+
import org.junit.jupiter.api.Test;
5+
6+
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
77

88
class EulerProblem01Test {
99

examples/maven-demo/src/test/java/info/jab/demo/EulerProblem02Test.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package info.jab.demo;
22

3-
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
4-
5-
import org.junit.jupiter.api.Test;
63
import info.jab.demo.utils.EulerAnswersLoader;
4+
import org.junit.jupiter.api.Test;
5+
6+
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
77

88
public class EulerProblem02Test {
99

0 commit comments

Comments
 (0)