Skip to content

Commit cecd416

Browse files
committed
Improving 110-java-maven-best-practices
1 parent 5d6b91b commit cecd416

5 files changed

Lines changed: 45 additions & 31 deletions

File tree

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Description: Use the `<dependencyManagement>` section in parent POMs or import B
9494
</project>
9595
```
9696

97-
**Bad Example:**
97+
**Bad example:**
9898

9999
```xml
100100
<!-- Child POM hardcoding versions -->
@@ -127,7 +127,7 @@ Description: Follow Maven's convention for directory structure (`src/main/java`,
127127

128128
**Good example:**
129129

130-
```
130+
```text
131131
my-app/
132132
├── pom.xml
133133
└── src/
@@ -141,11 +141,12 @@ my-app/
141141
│ └── com/example/myapp/AppTest.java
142142
└── resources/
143143
└── test-data.xml
144+
144145
```
145146

146-
**Bad Example:**
147+
**Bad example:**
147148

148-
```
149+
```text
149150
my-app/
150151
├── pom.xml
151152
├── sources/ <!-- Non-standard -->
@@ -155,6 +156,7 @@ my-app/
155156
└── tests/ <!-- Non-standard -->
156157
└── com/example/myapp/AppTest.java
157158
<!-- This would require explicit configuration in pom.xml to specify source/resource directories -->
159+
158160
```
159161

160162
## Rule 3: Plugin Management and Configuration
@@ -200,7 +202,7 @@ Description: Use `<pluginManagement>` in a parent POM to define plugin versions
200202
</project>
201203
```
202204

203-
**Bad Example:**
205+
**Bad example:**
204206

205207
```xml
206208
<!-- Child POM -->
@@ -272,9 +274,10 @@ Description: Use Maven profiles to customize build settings for different enviro
272274
</profiles>
273275
</project>
274276
<!-- Activation: mvn clean install -P prod -->
277+
275278
```
276279

277-
**Bad Example:**
280+
**Bad example:**
278281

279282
```xml
280283
<!-- Commented out sections for different environments -->
@@ -346,7 +349,7 @@ Description: Organize your `pom.xml` sections in a consistent order (e.g., proje
346349
</project>
347350
```
348351

349-
**Bad Example:**
352+
**Bad example:**
350353

351354
```xml
352355
<!-- Haphazard order, missing properties for versions -->
@@ -397,7 +400,7 @@ Description: Prefer dependencies from Maven Central. If custom repositories are
397400
<!-- Better: Configure these in settings.xml and use a repository manager -->
398401
```
399402

400-
**Bad Example:**
403+
**Bad example:**
401404

402405
```xml
403406
<!-- No explicit repository for a non-central artifact, relying on developer's local settings or transitive ones -->
@@ -436,22 +439,22 @@ Description: Define all dependency and plugin versions in the `<properties>` sec
436439
<maven.version>3.9.10</maven.version>
437440
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
438441
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
439-
442+
440443
<!-- Dependency versions -->
441444
<jackson.version>2.15.3</jackson.version>
442445
<junit.version>5.10.1</junit.version>
443446
<mockito.version>5.7.0</mockito.version>
444447
<logback.version>1.4.11</logback.version>
445-
448+
446449
<!-- Maven plugin versions -->
447450
<maven-plugin-compiler.version>3.14.0</maven-plugin-compiler.version>
448451
<maven-plugin-surefire.version>3.5.3</maven-plugin-surefire.version>
449452
<maven-plugin-failsafe.version>3.5.3</maven-plugin-failsafe.version>
450453
<maven-plugin-enforcer.version>3.5.0</maven-plugin-enforcer.version>
451-
454+
452455
<!-- Third-party plugin versions -->
453456
<maven-plugin-jacoco.version>0.8.13</maven-plugin-jacoco.version>
454-
457+
455458
<!-- Quality thresholds -->
456459
<coverage.level>80</coverage.level>
457460
<mutation.level>70</mutation.level>
@@ -503,7 +506,7 @@ Description: Define all dependency and plugin versions in the `<properties>` sec
503506
</project>
504507
```
505508

506-
**Bad Example:**
509+
**Bad example:**
507510

508511
```xml
509512
<!-- Hardcoded versions scattered throughout the POM -->

spml/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@
230230
<directory>${project.basedir}/src/test/resources</directory>
231231
<includes>
232232
<include>100-java-checklist-guide.mdc</include>
233+
<include>110-java-maven-best-practices.mdc</include>
233234
</includes>
234235
</resource>
235236
</resources>

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

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
</system-characterization>
2424

2525
<description>
26-
Effective Maven usage involves robust dependency management via `&lt;dependencyManagement&gt;` and BOMs, adherence to the standard directory layout, and centralized plugin management. Build profiles should be used for environment-specific configurations. POMs must be kept readable and maintainable with logical structure and properties for versions. Custom repositories should be declared explicitly and their use minimized, preferably managed via a central repository manager.
26+
<![CDATA[
27+
Effective Maven usage involves robust dependency management via `<dependencyManagement>` and BOMs, adherence to the standard directory layout, and centralized plugin management. Build profiles should be used for environment-specific configurations. POMs must be kept readable and maintainable with logical structure and properties for versions. Custom repositories should be declared explicitly and their use minimized, preferably managed via a central repository manager.
28+
]]>
2729
</description>
2830

2931
<toc auto-generate="true"/>
@@ -35,7 +37,9 @@
3537
<rule-subtitle>Manage Dependencies Effectively using `dependencyManagement` and BOMs</rule-subtitle>
3638
</rule-header>
3739
<rule-description>
38-
Use the `&lt;dependencyManagement&gt;` section in parent POMs or import Bill of Materials (BOMs) to centralize and control dependency versions. This helps avoid version conflicts and ensures consistency across multi-module projects. Avoid hardcoding versions directly in `&lt;dependencies&gt;` when managed elsewhere.
40+
<![CDATA[
41+
Use the `<dependencyManagement>` section in parent POMs or import Bill of Materials (BOMs) to centralize and control dependency versions. This helps avoid version conflicts and ensures consistency across multi-module projects. Avoid hardcoding versions directly in `<dependencies>` when managed elsewhere.
42+
]]>
3943
</rule-description>
4044
<code-examples>
4145
<good-example>
@@ -133,11 +137,12 @@
133137
<rule-subtitle>Adhere to the Standard Directory Layout</rule-subtitle>
134138
</rule-header>
135139
<rule-description>
136-
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.
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.]]>
137141
</rule-description>
138142
<code-examples>
139143
<good-example>
140-
<code-block>my-app/
144+
<code-block language="text"><![CDATA[
145+
my-app/
141146
├── pom.xml
142147
└── src/
143148
├── main/
@@ -149,18 +154,21 @@
149154
├── java/
150155
│ └── com/example/myapp/AppTest.java
151156
└── resources/
152-
└── test-data.xml</code-block>
157+
└── test-data.xml
158+
]]></code-block>
153159
</good-example>
154160
<bad-example>
155-
<code-block>my-app/
161+
<code-block language="text"><![CDATA[
162+
my-app/
156163
├── pom.xml
157-
├── sources/ &lt;!-- Non-standard --&gt;
164+
├── sources/ <!-- Non-standard -->
158165
│ └── com/example/myapp/App.java
159-
├── res/ &lt;!-- Non-standard --&gt;
166+
├── res/ <!-- Non-standard -->
160167
│ └── config.properties
161-
└── tests/ &lt;!-- Non-standard --&gt;
168+
└── tests/ <!-- Non-standard -->
162169
└── com/example/myapp/AppTest.java
163-
&lt;!-- This would require explicit configuration in pom.xml to specify source/resource directories --&gt;</code-block>
170+
<!-- This would require explicit configuration in pom.xml to specify source/resource directories -->
171+
]]></code-block>
164172
</bad-example>
165173
</code-examples>
166174
</rule-section>
@@ -171,7 +179,7 @@
171179
<rule-subtitle>Manage Plugin Versions and Configurations Centrally</rule-subtitle>
172180
</rule-header>
173181
<rule-description>
174-
Use `&lt;pluginManagement&gt;` 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.
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.]]>
175183
</rule-description>
176184
<code-examples>
177185
<good-example>
@@ -237,7 +245,7 @@
237245
<rule-subtitle>Employ Build Profiles for Environment-Specific Settings</rule-subtitle>
238246
</rule-header>
239247
<rule-description>
240-
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.
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.]]>
241249
</rule-description>
242250
<code-examples>
243251
<good-example>
@@ -306,7 +314,7 @@
306314
<rule-subtitle>Structure POMs Logically for Readability</rule-subtitle>
307315
</rule-header>
308316
<rule-description>
309-
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.
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.]]>
310318
</rule-description>
311319
<code-examples>
312320
<good-example>
@@ -393,7 +401,7 @@
393401
<rule-subtitle>Declare Custom Repositories Explicitly and Minimize Their Use</rule-subtitle>
394402
</rule-header>
395403
<rule-description>
396-
Prefer dependencies from Maven Central. If custom repositories are necessary, declare them in the `&lt;repositories&gt;` section and `&lt;pluginRepositories&gt;` 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.
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.]]>
397405
</rule-description>
398406
<code-examples>
399407
<good-example>
@@ -441,7 +449,7 @@
441449
<rule-subtitle>Use Properties to Manage Dependency and Plugin Versions</rule-subtitle>
442450
</rule-header>
443451
<rule-description>
444-
Define all dependency and plugin versions in the `&lt;properties&gt;` 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`.
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`.]]>
445453
</rule-description>
446454
<code-examples>
447455
<good-example>

spml/src/test/java/info/jab/xml/CursorRuleGeneratorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ void should_produceConsistentStructure_when_processingDifferentXmlTypes() throws
347347

348348
// Save all for comparison
349349
saveGeneratedContentToTarget(checklistGuideResult, "100-java-checklist-guide.mdc");
350-
//saveGeneratedContentToTarget(bestPracticesResult, "unified-best-practices.mdc");
350+
saveGeneratedContentToTarget(bestPracticesResult, "110-java-maven-best-practices.mdc");
351351
//saveGeneratedContentToTarget(documentationResult, "unified-documentation.mdc");
352352
//saveGeneratedContentToTarget(objectOrientedDesignResult, "unified-object-oriented-design.mdc");
353353
//saveGeneratedContentToTarget(typeDesignResult, "unified-type-design.mdc");

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ Description: Follow Maven's convention for directory structure (`src/main/java`,
127127

128128
**Good example:**
129129

130-
```
130+
```text
131131
my-app/
132132
├── pom.xml
133133
└── src/
@@ -141,11 +141,12 @@ my-app/
141141
│ └── com/example/myapp/AppTest.java
142142
└── resources/
143143
└── test-data.xml
144+
144145
```
145146

146147
**Bad example:**
147148

148-
```
149+
```text
149150
my-app/
150151
├── pom.xml
151152
├── sources/ <!-- Non-standard -->
@@ -155,6 +156,7 @@ my-app/
155156
└── tests/ <!-- Non-standard -->
156157
└── com/example/myapp/AppTest.java
157158
<!-- This would require explicit configuration in pom.xml to specify source/resource directories -->
159+
158160
```
159161

160162
## Rule 3: Plugin Management and Configuration

0 commit comments

Comments
 (0)