You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .cursor/rules/110-java-maven-best-practices.mdc
+21-26Lines changed: 21 additions & 26 deletions
Original file line number
Diff line number
Diff line change
@@ -5,31 +5,27 @@ alwaysApply: false
5
5
---
6
6
# Maven Best Practices
7
7
8
-
## System prompt characterization
9
-
10
-
Role definition: You are a Senior software engineer with extensive experience in Java software development
11
-
12
-
## Description
13
-
14
-
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.
8
+
## Instructions for AI
15
9
16
-
## Table of contents
10
+
Update the pom.xml based on the following rules about Maven best practices.
17
11
18
-
- Rule 1: Effective Dependency Management
19
-
- Rule 2: Standard Directory Layout
20
-
- Rule 3: Plugin Management and Configuration
21
-
- Rule 4: Use Build Profiles for Environment-Specific Configurations
22
-
- Rule 5: Keep POMs Readable and Maintainable
23
-
- Rule 6: Manage Repositories Explicitly
24
-
- Rule 7: Centralize Version Management with Properties
12
+
## Role
25
13
14
+
You are a Senior software engineer with extensive experience in Java software development
26
15
27
-
## Instructions for AI
16
+
## Examples
28
17
29
-
Update the pom.xml based on the following rules about Maven best practices.
18
+
### Table of contents
30
19
20
+
- Example 1: Effective Dependency Management
21
+
- Example 2: Standard Directory Layout
22
+
- Example 3: Plugin Management and Configuration
23
+
- Example 4: Use Build Profiles for Environment-Specific Configurations
24
+
- Example 5: Keep POMs Readable and Maintainable
25
+
- Example 6: Manage Repositories Explicitly
26
+
- Example 7: Centralize Version Management with Properties
31
27
32
-
## Rule 1: Effective Dependency Management
28
+
### Example 1: Effective Dependency Management
33
29
34
30
Title: Manage Dependencies Effectively using `dependencyManagement` and BOMs
35
31
Description: 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.
@@ -128,7 +124,7 @@ Description: Use the `<dependencyManagement>` section in parent POMs or import B
128
124
129
125
```
130
126
131
-
## Rule 2: Standard Directory Layout
127
+
### Example 2: Standard Directory Layout
132
128
133
129
Title: Adhere to the Standard Directory Layout
134
130
Description: 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.
@@ -167,7 +163,7 @@ my-app/
167
163
168
164
```
169
165
170
-
## Rule 3: Plugin Management and Configuration
166
+
### Example 3: Plugin Management and Configuration
171
167
172
168
Title: Manage Plugin Versions and Configurations Centrally
173
169
Description: 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.
@@ -234,7 +230,7 @@ Description: Use `<pluginManagement>` in a parent POM to define plugin versions
234
230
235
231
```
236
232
237
-
## Rule 4: Use Build Profiles for Environment-Specific Configurations
233
+
### Example 4: Use Build Profiles for Environment-Specific Configurations
238
234
239
235
Title: Employ Build Profiles for Environment-Specific Settings
240
236
Description: 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.
@@ -301,7 +297,7 @@ Description: Use Maven profiles to customize build settings for different enviro
301
297
302
298
```
303
299
304
-
## Rule 5: Keep POMs Readable and Maintainable
300
+
### Example 5: Keep POMs Readable and Maintainable
305
301
306
302
Title: Structure POMs Logically for Readability
307
303
Description: 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.
@@ -387,7 +383,7 @@ Description: Organize your `pom.xml` sections in a consistent order (e.g., proje
387
383
388
384
```
389
385
390
-
## Rule 6: Manage Repositories Explicitly
386
+
### Example 6: Manage Repositories Explicitly
391
387
392
388
Title: Declare Custom Repositories Explicitly and Minimize Their Use
393
389
Description: 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.
@@ -434,7 +430,7 @@ Description: Prefer dependencies from Maven Central. If custom repositories are
434
430
435
431
```
436
432
437
-
## Rule 7: Centralize Version Management with Properties
433
+
### Example 7: Centralize Version Management with Properties
438
434
439
435
Title: Use Properties to Manage Dependency and Plugin Versions
440
436
Description: 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`.
@@ -589,8 +585,7 @@ Description: Define all dependency and plugin versions in the `<properties>` sec
589
585
590
586
```
591
587
592
-
593
588
## Output Requirements
594
589
595
590
- Update the file pom.xml if something is not correct
0 commit comments