Skip to content

Commit 7844bc3

Browse files
committed
Minor improvement in the xml
1 parent cecd416 commit 7844bc3

3 files changed

Lines changed: 72 additions & 22 deletions

File tree

.cursor/rules/110-java-maven-best-practices.mdc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ Description: Use the `<dependencyManagement>` section in parent POMs or import B
9292
</dependency>
9393
</dependencies>
9494
</project>
95+
9596
```
9697

9798
**Bad example:**
@@ -118,6 +119,7 @@ Description: Use the `<dependencyManagement>` section in parent POMs or import B
118119
</dependency>
119120
</dependencies>
120121
</project>
122+
121123
```
122124

123125
## Rule 2: Standard Directory Layout
@@ -200,6 +202,7 @@ Description: Use `<pluginManagement>` in a parent POM to define plugin versions
200202
</plugins>
201203
</build>
202204
</project>
205+
203206
```
204207

205208
**Bad example:**
@@ -222,6 +225,7 @@ Description: Use `<pluginManagement>` in a parent POM to define plugin versions
222225
</plugins>
223226
</build>
224227
</project>
228+
225229
```
226230

227231
## Rule 4: Use Build Profiles for Environment-Specific Configurations
@@ -288,6 +292,7 @@ Description: Use Maven profiles to customize build settings for different enviro
288292
<database.url>jdbc:postgresql://prodserver/mydb</database.url> <!-- Manually switch by commenting/uncommenting -->
289293
</properties>
290294
</project>
295+
291296
```
292297

293298
## Rule 5: Keep POMs Readable and Maintainable
@@ -347,6 +352,7 @@ Description: Organize your `pom.xml` sections in a consistent order (e.g., proje
347352
<!-- Repositories and Plugin Repositories (if needed) -->
348353
<!-- ... -->
349354
</project>
355+
350356
```
351357

352358
**Bad example:**
@@ -372,6 +378,7 @@ Description: Organize your `pom.xml` sections in a consistent order (e.g., proje
372378
<artifactId>my-app</artifactId>
373379
<version>1.0.0-SNAPSHOT</version>
374380
</project>
381+
375382
```
376383

377384
## Rule 6: Manage Repositories Explicitly
@@ -398,6 +405,7 @@ Description: Prefer dependencies from Maven Central. If custom repositories are
398405
</pluginRepositories>
399406
</project>
400407
<!-- Better: Configure these in settings.xml and use a repository manager -->
408+
401409
```
402410

403411
**Bad example:**
@@ -417,6 +425,7 @@ Description: Prefer dependencies from Maven Central. If custom repositories are
417425
</dependency>
418426
</dependencies>
419427
</project>
428+
420429
```
421430

422431
## Rule 7: Centralize Version Management with Properties
@@ -504,6 +513,7 @@ Description: Define all dependency and plugin versions in the `<properties>` sec
504513
</plugins>
505514
</build>
506515
</project>
516+
507517
```
508518

509519
**Bad example:**
@@ -570,4 +580,5 @@ Description: Define all dependency and plugin versions in the `<properties>` sec
570580
</plugins>
571581
</build>
572582
</project>
583+
573584
```

spml/src/main/resources/110-java-maven-best-practices.xml

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
</rule-description>
4444
<code-examples>
4545
<good-example>
46-
<code-block language="xml"><![CDATA[<!-- Parent POM -->
46+
<code-block language="xml"><![CDATA[
47+
<!-- Parent POM -->
4748
<project>
4849
<modelVersion>4.0.0</modelVersion>
4950
<groupId>com.example</groupId>
@@ -103,10 +104,12 @@
103104
<!-- Version and scope inherited -->
104105
</dependency>
105106
</dependencies>
106-
</project>]]></code-block>
107+
</project>
108+
]]></code-block>
107109
</good-example>
108110
<bad-example>
109-
<code-block language="xml"><![CDATA[<!-- Child POM hardcoding versions -->
111+
<code-block language="xml"><![CDATA[
112+
<!-- Child POM hardcoding versions -->
110113
<project>
111114
<modelVersion>4.0.0</modelVersion>
112115
<groupId>com.example</groupId>
@@ -126,7 +129,8 @@
126129
<scope>test</scope>
127130
</dependency>
128131
</dependencies>
129-
</project>]]></code-block>
132+
</project>
133+
]]></code-block>
130134
</bad-example>
131135
</code-examples>
132136
</rule-section>
@@ -137,7 +141,9 @@
137141
<rule-subtitle>Adhere to the Standard Directory Layout</rule-subtitle>
138142
</rule-header>
139143
<rule-description>
140-
<![CDATA[Follow Maven's convention for directory structure (`src/main/java`, `src/main/resources`, `src/test/java`, `src/test/resources`, etc.). This makes projects easier to understand and build, as Maven relies on these defaults.]]>
144+
<![CDATA[
145+
Follow Maven's convention for directory structure (`src/main/java`, `src/main/resources`, `src/test/java`, `src/test/resources`, etc.). This makes projects easier to understand and build, as Maven relies on these defaults.
146+
]]>
141147
</rule-description>
142148
<code-examples>
143149
<good-example>
@@ -179,11 +185,14 @@ my-app/
179185
<rule-subtitle>Manage Plugin Versions and Configurations Centrally</rule-subtitle>
180186
</rule-header>
181187
<rule-description>
182-
<![CDATA[Use `<pluginManagement>` in a parent POM to define plugin versions and common configurations. Child POMs can then use the plugins without specifying versions, ensuring consistency. Override configurations in child POMs only when necessary.]]>
188+
<![CDATA[
189+
Use `<pluginManagement>` in a parent POM to define plugin versions and common configurations. Child POMs can then use the plugins without specifying versions, ensuring consistency. Override configurations in child POMs only when necessary.
190+
]]>
183191
</rule-description>
184192
<code-examples>
185193
<good-example>
186-
<code-block language="xml"><![CDATA[<!-- Parent POM -->
194+
<code-block language="xml"><![CDATA[
195+
<!-- Parent POM -->
187196
<project>
188197
<!-- ... -->
189198
<build>
@@ -215,10 +224,12 @@ my-app/
215224
</plugin>
216225
</plugins>
217226
</build>
218-
</project>]]></code-block>
227+
</project>
228+
]]></code-block>
219229
</good-example>
220230
<bad-example>
221-
<code-block language="xml"><![CDATA[<!-- Child POM -->
231+
<code-block language="xml"><![CDATA[
232+
<!-- Child POM -->
222233
<project>
223234
<!-- ... -->
224235
<build>
@@ -234,7 +245,8 @@ my-app/
234245
</plugin>
235246
</plugins>
236247
</build>
237-
</project>]]></code-block>
248+
</project>
249+
]]></code-block>
238250
</bad-example>
239251
</code-examples>
240252
</rule-section>
@@ -245,7 +257,9 @@ my-app/
245257
<rule-subtitle>Employ Build Profiles for Environment-Specific Settings</rule-subtitle>
246258
</rule-header>
247259
<rule-description>
248-
<![CDATA[Use Maven profiles to customize build settings for different environments (e.g., dev, test, prod) or other conditional scenarios. This can include different dependencies, plugin configurations, or properties. Activate profiles via command line, OS, JDK, or file presence.]]>
260+
<![CDATA[
261+
Use Maven profiles to customize build settings for different environments (e.g., dev, test, prod) or other conditional scenarios. This can include different dependencies, plugin configurations, or properties. Activate profiles via command line, OS, JDK, or file presence.
262+
]]>
249263
</rule-description>
250264
<code-examples>
251265
<good-example>
@@ -303,7 +317,8 @@ my-app/
303317
<!-- <database.url>jdbc:h2:mem:devdb</database.url> -->
304318
<database.url>jdbc:postgresql://prodserver/mydb</database.url> <!-- Manually switch by commenting/uncommenting -->
305319
</properties>
306-
</project>]]></code-block>
320+
</project>
321+
]]></code-block>
307322
</bad-example>
308323
</code-examples>
309324
</rule-section>
@@ -314,7 +329,9 @@ my-app/
314329
<rule-subtitle>Structure POMs Logically for Readability</rule-subtitle>
315330
</rule-header>
316331
<rule-description>
317-
<![CDATA[Organize your `pom.xml` sections in a consistent order (e.g., project coordinates, parent, properties, dependencyManagement, dependencies, build, profiles, repositories). Use properties for recurring versions or values. Add comments for complex configurations.]]>
332+
<![CDATA[
333+
Organize your `pom.xml` sections in a consistent order (e.g., project coordinates, parent, properties, dependencyManagement, dependencies, build, profiles, repositories). Use properties for recurring versions or values. Add comments for complex configurations.
334+
]]>
318335
</rule-description>
319336
<code-examples>
320337
<good-example>
@@ -367,7 +384,8 @@ my-app/
367384
368385
<!-- Repositories and Plugin Repositories (if needed) -->
369386
<!-- ... -->
370-
</project>]]></code-block>
387+
</project>
388+
]]></code-block>
371389
</good-example>
372390
<bad-example>
373391
<code-block language="xml"><![CDATA[
@@ -390,7 +408,8 @@ my-app/
390408
</properties>
391409
<artifactId>my-app</artifactId>
392410
<version>1.0.0-SNAPSHOT</version>
393-
</project>]]></code-block>
411+
</project>
412+
]]></code-block>
394413
</bad-example>
395414
</code-examples>
396415
</rule-section>
@@ -401,7 +420,9 @@ my-app/
401420
<rule-subtitle>Declare Custom Repositories Explicitly and Minimize Their Use</rule-subtitle>
402421
</rule-header>
403422
<rule-description>
404-
<![CDATA[Prefer dependencies from Maven Central. If custom repositories are necessary, declare them in the `<repositories>` section and `<pluginRepositories>` for plugins. It's often better to manage these in a company-wide Nexus/Artifactory instance configured in `settings.xml` rather than per-project POMs. Avoid relying on transitive repositories.]]>
423+
<![CDATA[
424+
Prefer dependencies from Maven Central. If custom repositories are necessary, declare them in the `<repositories>` section and `<pluginRepositories>` for plugins. It's often better to manage these in a company-wide Nexus/Artifactory instance configured in `settings.xml` rather than per-project POMs. Avoid relying on transitive repositories.
425+
]]>
405426
</rule-description>
406427
<code-examples>
407428
<good-example>
@@ -421,7 +442,8 @@ my-app/
421442
</pluginRepository>
422443
</pluginRepositories>
423444
</project>
424-
<!-- Better: Configure these in settings.xml and use a repository manager -->]]></code-block>
445+
<!-- Better: Configure these in settings.xml and use a repository manager -->
446+
]]></code-block>
425447
</good-example>
426448
<bad-example>
427449
<code-block language="xml"><![CDATA[
@@ -438,7 +460,8 @@ my-app/
438460
Relying on implicit configurations makes builds less portable. -->
439461
</dependency>
440462
</dependencies>
441-
</project>]]></code-block>
463+
</project>
464+
]]></code-block>
442465
</bad-example>
443466
</code-examples>
444467
</rule-section>
@@ -449,7 +472,9 @@ my-app/
449472
<rule-subtitle>Use Properties to Manage Dependency and Plugin Versions</rule-subtitle>
450473
</rule-header>
451474
<rule-description>
452-
<![CDATA[Define all dependency and plugin versions in the `<properties>` section rather than hardcoding them throughout the POM. This centralizes version management, makes updates easier, reduces duplication, and helps maintain consistency across related dependencies. Use consistent property naming conventions: `maven-plugin-[name].version` for Maven plugins, simple names like `[library].version` for dependencies, and descriptive names for quality thresholds like `coverage.level`.]]>
475+
<![CDATA[
476+
Define all dependency and plugin versions in the `<properties>` section rather than hardcoding them throughout the POM. This centralizes version management, makes updates easier, reduces duplication, and helps maintain consistency across related dependencies. Use consistent property naming conventions: `maven-plugin-[name].version` for Maven plugins, simple names like `[library].version` for dependencies, and descriptive names for quality thresholds like `coverage.level`.
477+
]]>
453478
</rule-description>
454479
<code-examples>
455480
<good-example>
@@ -530,10 +555,12 @@ my-app/
530555
</plugin>
531556
</plugins>
532557
</build>
533-
</project>]]></code-block>
558+
</project>
559+
]]></code-block>
534560
</good-example>
535561
<bad-example>
536-
<code-block language="xml"><![CDATA[<!-- Hardcoded versions scattered throughout the POM -->
562+
<code-block language="xml"><![CDATA[
563+
<!-- Hardcoded versions scattered throughout the POM -->
537564
<project>
538565
<modelVersion>4.0.0</modelVersion>
539566
<groupId>com.example</groupId>
@@ -593,7 +620,8 @@ my-app/
593620
</plugin>
594621
</plugins>
595622
</build>
596-
</project>]]></code-block>
623+
</project>
624+
]]></code-block>
597625
</bad-example>
598626
</code-examples>
599627
</rule-section>

spml/src/test/resources/110-java-maven-best-practices.mdc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ Description: Use the `<dependencyManagement>` section in parent POMs or import B
9292
</dependency>
9393
</dependencies>
9494
</project>
95+
9596
```
9697

9798
**Bad example:**
@@ -118,6 +119,7 @@ Description: Use the `<dependencyManagement>` section in parent POMs or import B
118119
</dependency>
119120
</dependencies>
120121
</project>
122+
121123
```
122124

123125
## Rule 2: Standard Directory Layout
@@ -200,6 +202,7 @@ Description: Use `<pluginManagement>` in a parent POM to define plugin versions
200202
</plugins>
201203
</build>
202204
</project>
205+
203206
```
204207

205208
**Bad example:**
@@ -222,6 +225,7 @@ Description: Use `<pluginManagement>` in a parent POM to define plugin versions
222225
</plugins>
223226
</build>
224227
</project>
228+
225229
```
226230

227231
## Rule 4: Use Build Profiles for Environment-Specific Configurations
@@ -288,6 +292,7 @@ Description: Use Maven profiles to customize build settings for different enviro
288292
<database.url>jdbc:postgresql://prodserver/mydb</database.url> <!-- Manually switch by commenting/uncommenting -->
289293
</properties>
290294
</project>
295+
291296
```
292297

293298
## Rule 5: Keep POMs Readable and Maintainable
@@ -347,6 +352,7 @@ Description: Organize your `pom.xml` sections in a consistent order (e.g., proje
347352
<!-- Repositories and Plugin Repositories (if needed) -->
348353
<!-- ... -->
349354
</project>
355+
350356
```
351357

352358
**Bad example:**
@@ -372,6 +378,7 @@ Description: Organize your `pom.xml` sections in a consistent order (e.g., proje
372378
<artifactId>my-app</artifactId>
373379
<version>1.0.0-SNAPSHOT</version>
374380
</project>
381+
375382
```
376383

377384
## Rule 6: Manage Repositories Explicitly
@@ -398,6 +405,7 @@ Description: Prefer dependencies from Maven Central. If custom repositories are
398405
</pluginRepositories>
399406
</project>
400407
<!-- Better: Configure these in settings.xml and use a repository manager -->
408+
401409
```
402410

403411
**Bad example:**
@@ -417,6 +425,7 @@ Description: Prefer dependencies from Maven Central. If custom repositories are
417425
</dependency>
418426
</dependencies>
419427
</project>
428+
420429
```
421430

422431
## Rule 7: Centralize Version Management with Properties
@@ -504,6 +513,7 @@ Description: Define all dependency and plugin versions in the `<properties>` sec
504513
</plugins>
505514
</build>
506515
</project>
516+
507517
```
508518

509519
**Bad example:**
@@ -570,4 +580,5 @@ Description: Define all dependency and plugin versions in the `<properties>` sec
570580
</plugins>
571581
</build>
572582
</project>
583+
573584
```

0 commit comments

Comments
 (0)