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/114-java-maven-search.md
+92-23Lines changed: 92 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
2
name: 114-java-maven-search
3
-
description: Provides comprehensive guidance for searching and retrieving Maven components from Maven Central Repository (https://repo1.maven.org/maven2/). Use when the user needs to find, verify, or retrieve Maven dependencies, check component versions, analyze dependency trees, or work with Maven coordinates (groupId, artifactId, version), POMs, JARs, sources, or Javadoc.
3
+
description: Provides guidance for (1) Maven Central search and coordinates via the Search API and repository URLs, and (2) project-local checks for newer dependency, plugin, and property versions using the Versions Maven Plugin. Use when the user needs to findor verify artifacts, browse versions, inspect POMs, or see what updates apply to their own pom.xml.
4
4
license: Apache-2.0
5
5
metadata:
6
6
author: Juan Antonio Breña Moral
@@ -14,9 +14,15 @@ You are a Senior software engineer with extensive experience in Java software de
14
14
15
15
## Goal
16
16
17
-
Guide search and retrieval of artifacts from **Maven Central** using the public **Search API** and **direct repository URLs**. Help the user discover coordinates, inspect version history via `maven-metadata.xml`, download POMs and JARs, reason about transitive dependencies from POMs, and present results as `groupId:artifactId:version` with verifiable links.
17
+
Guide two related workflows:
18
18
19
-
**Apply this guidance when the user mentions:** searching for Maven dependencies or components; finding or verifying coordinates; version history or latest versions; downloading JAR, POM, sources, or Javadoc; Maven Central or repository URLs; dependency trees or transitive dependencies; or keywords such as groupId, artifactId, repository, artifact (including Chinese phrases about Maven 依赖, 坐标, 版本, 中央仓库, 传递依赖, 依赖树).
19
+
1.**Maven Central search** — Use the public **Search API** and **direct repository URLs** to discover coordinates, read `maven-metadata.xml`, download POMs and JARs, reason about dependencies from POMs, and present `groupId:artifactId:version` with verifiable links.
20
+
21
+
2.**Project update reports** — When the user wants to see **newer versions of dependencies, build plugins, or `${property}`-driven versions** already declared in their project, ensure the **Versions Maven Plugin** (`org.codehaus.mojo:versions-maven-plugin`) is present in the POM, then run the appropriate `versions:display-*` goals (see Step 2).
22
+
23
+
**Apply Central-search guidance when the user mentions:** searching for Maven dependencies or components; finding or verifying coordinates; version history or latest versions on Central; downloading JAR, POM, sources, or Javadoc; Maven Central or repository URLs; dependency trees or transitive dependencies; or keywords such as groupId, artifactId, repository, artifact (including Chinese phrases about Maven 依赖, 坐标, 版本, 中央仓库, 传递依赖, 依赖树).
24
+
25
+
**Apply Versions-plugin guidance when the user mentions:** outdated dependencies in *their* project, available updates, `display-dependency-updates`, plugin updates, or property version bumps for their `pom.xml`.
20
26
21
27
22
28
## Constraints
@@ -30,7 +36,7 @@ Prefer authoritative sources: Maven Central Search API responses, `maven-metadat
30
36
31
37
## Steps
32
38
33
-
### Step 1: Recognize the task and search pattern
39
+
### Step 1: Recognize the task and branch (Central search vs. project updates)
34
40
35
41
Classify the request before choosing a tool:
36
42
@@ -41,16 +47,67 @@ Classify the request before choosing a tool:
41
47
| Latest or all versions for a fixed G:A|`maven-metadata.xml` under the artifact directory |
42
48
| Inspect dependencies | Fetch and parse the POM for that version |
43
49
| Download binary, sources, or Javadoc | Direct URL under `.../{version}/`|
50
+
|**See newer versions for dependencies, plugins, or `${property}` placeholders already in *this* project’s POM**|**Step 2** — Versions Maven Plugin (`versions:display-*` goals) |
51
+
52
+
**Branching**
53
+
54
+
- If the user wants **Maven Central search** (discover artifacts, coordinates, metadata, downloads, or transitive insight from a published POM), **skip Step 2** and continue from Step 3 onward.
55
+
- If the user wants **update information for their own `pom.xml`** (what newer versions exist for declared deps/plugins/properties), **use Step 2** first. You may still use Steps 3+ afterward to look up unfamiliar GAVs on Central.
44
56
45
57
**Search API base:**`https://search.maven.org/solrsearch/select`
**Path rule:** groupId segments become directories (`com.google.guava` → `com/google/guava`); artifactId is its own path segment; version is the next segment; files are named `{artifactId}-{version}.{ext}`.### Step 2: Query the Maven Central Search API
61
+
**Path rule:** groupId segments become directories (`org.springframework.boot` → `org/springframework/boot`); artifactId is its own path segment; version is the next segment; files are named `{artifactId}-{version}.{ext}`.
62
+
63
+
### Step 2: Project updates: verify Versions Maven Plugin, then run display goals
64
+
65
+
Use this step when the user asks what can be updated **in their project** (dependencies, build plugins, or versions driven
66
+
by Maven properties)—not when they only want to **search Maven Central** for a library by name.
67
+
68
+
**1. Verify the plugin is declared**
69
+
70
+
Inspect the project's effective POM sources (root and parent chain)
71
+
for **`org.codehaus.mojo:versions-maven-plugin`** under `<build><plugins>` or `<build><pluginManagement><plugins>`.
72
+
73
+
**2. If it is missing, add it**
74
+
75
+
Add a `<plugin>` entry with `groupId``org.codehaus.mojo`, `artifactId``versions-maven-plugin`,
76
+
and a **`version`** set to a **current release** from Maven Central (do not invent a version—resolve it
77
+
via Search API/metadata or the plugin's documentation). A minimal declaration:
78
+
79
+
```xml
80
+
<plugin>
81
+
<groupId>org.codehaus.mojo</groupId>
82
+
<artifactId>versions-maven-plugin</artifactId>
83
+
<version><!-- current release from Maven Central --></version>
84
+
</plugin>
85
+
```
86
+
87
+
Prefer `pluginManagement` in the parent POM for multi-module builds; otherwise place under `<build><plugins>` in the module that owns the build.
88
+
89
+
**3. Run these goals from the project root** (use the Maven Wrapper when present):
90
+
91
+
```bash
92
+
./mvnw versions:display-property-updates
93
+
./mvnw versions:display-dependency-updates
94
+
./mvnw versions:display-plugin-updates
95
+
```
96
+
97
+
Use `mvn` instead of `./mvnw` only when the project has no wrapper. Interpretation:
98
+
99
+
-**`display-property-updates`** — suggests newer values for version **properties** referenced in the POM (e.g. `${foo.version}`).
100
+
-**`display-dependency-updates`** — suggests newer versions for **dependencies** (respecting scopes and management rules).
101
+
-**`display-plugin-updates`** — suggests newer versions for **build plugins** (including reporting plugins where applicable).
102
+
103
+
These commands complement Central search: they answer “what is newer **for this build**,” while Steps 3-9
104
+
help **discover and verify** arbitrary artifacts on Central.
105
+
106
+
**Reference:**https://www.mojohaus.org/versions/versions-maven-plugin/### Step 3: Query the Maven Central Search API
Parse the JSON `response.docs[]` for `g`, `a`, `latestVersion` (or per-doc version fields as returned), and any description fields present. For official Search API documentation and evolution, see Sonatype Central Search API docs: https://central.sonatype.com/search-api/### Step 3: Read version history with maven-metadata.xml
128
+
Parse the JSON `response.docs[]` for `g`, `a`, `latestVersion` (or per-doc version fields as returned),
129
+
and any description fields present. For official Search API documentation and evolution,
130
+
see Sonatype Central Search API docs: https://central.sonatype.com/search-api/### Step 4: Read version history with maven-metadata.xml
72
131
73
132
For a known `groupId` and `artifactId`, version lists and `latest` / `release` hints are published at:
Use this when the user asks for “all versions”, “latest release”, or to compare version lines. Parent POMs may also publish metadata one level up when applicable to that layout.### Step 4: Build direct artifact URLs
144
+
Use this when the user asks for “all versions”, “latest release”, or to compare version lines.
145
+
Parent POMs may also publish metadata one level up when applicable to that layout.
Optional: checksums alongside artifacts (e.g. `.jar.sha1`, `.pom.sha1`) for verification.### Step 5: Analyze dependencies from a POM
172
+
Optional: checksums alongside artifacts (e.g. `.jar.sha1`, `.pom.sha1`) for verification.
173
+
174
+
### Step 6: Analyze dependencies from a POM
112
175
113
176
To reason about **direct** and **transitive** dependencies:
114
177
115
-
1. Download the resolved POM for the chosen GAV (Step 4).
178
+
1. Download the resolved POM for the chosen GAV (Step 5).
116
179
2. Read `<dependencies>`, `<dependencyManagement>`, and parent `<parent>` (may imply import BOMs or inherited dependencyManagement).
117
180
3. Explain that the **full transitive tree** for a project is best obtained with Maven (`mvn dependency:tree`) or Gradle equivalent on the **consumer** project — a single POM on Central does not replace resolver mediation, exclusions, or profiles.
118
181
119
-
Call out `<scope>`, `<optional>true</optional>`, and `<classifier>` when they affect what appears on the classpath.### Step 6: Validate and present results
182
+
Call out `<scope>`, `<optional>true</optional>`, and `<classifier>` when they affect what appears on the classpath.
183
+
### Step 7: Validate and present results
120
184
121
185
**Validation habits:**
122
186
@@ -131,23 +195,28 @@ Call out `<scope>`, `<optional>true</optional>`, and `<classifier>` when they af
131
195
- Include clickable HTTPS links to Search UI (`https://search.maven.org/`) or direct `repo1.maven.org` paths when useful.
If the user’s environment supports **MCP or tooling** for Maven Central (e.g. dependency intelligence servers), prefer those tools for live lookups when available, in addition to the URLs above.### Step 7: Quick task recipes
198
+
If the user’s environment supports **MCP or tooling** for Maven Central (e.g. dependency intelligence servers), prefer those tools for live lookups when available, in addition to the URLs above.
199
+
### Step 8: Quick task recipes
135
200
136
201
**Task A — Search by name:**`q=<keyword>` on the Search API.
137
202
138
203
**Task B — Search by G and A:**`q=g:<groupId> AND a:<artifactId>`.
139
204
140
205
**Task C — Version list / latest:** GET `maven-metadata.xml` for that G:A path.
141
206
142
-
**Task D — Download artifact:** Construct URL from Step 4 after confirming the version exists.
207
+
**Task D — Download artifact:** Construct URL from Step 5 after confirming the version exists.
208
+
209
+
**Task E — Dependency insight:** GET the POM, list direct dependencies; recommend `mvn dependency:tree` on the user’s project for the resolved graph.
143
210
144
-
**Task E — Dependency insight:** GET the POM, list direct dependencies; recommend `mvn dependency:tree` on the user’s project for the resolved graph.### Step 8: Keywords and resources
211
+
**Task F — Project update report (own POM):** Ensure `versions-maven-plugin` is present (Step 2), then run `./mvnw versions:display-property-updates`, `./mvnw versions:display-dependency-updates`, and `./mvnw versions:display-plugin-updates`.
0 commit comments