Skip to content

Commit 97c91b0

Browse files
committed
Improving Skill about search
1 parent 866a2bc commit 97c91b0

7 files changed

Lines changed: 304 additions & 80 deletions

File tree

.cursor/rules/114-java-maven-search.md

Lines changed: 92 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
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 find or verify artifacts, browse versions, inspect POMs, or see what updates apply to their own pom.xml.
44
license: Apache-2.0
55
metadata:
66
author: Juan Antonio Breña Moral
@@ -14,9 +14,15 @@ You are a Senior software engineer with extensive experience in Java software de
1414

1515
## Goal
1616

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:
1818

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`.
2026

2127

2228
## Constraints
@@ -30,7 +36,7 @@ Prefer authoritative sources: Maven Central Search API responses, `maven-metadat
3036

3137
## Steps
3238

33-
### Step 1: Recognize the task and search pattern
39+
### Step 1: Recognize the task and branch (Central search vs. project updates)
3440

3541
Classify the request before choosing a tool:
3642

@@ -41,16 +47,67 @@ Classify the request before choosing a tool:
4147
| Latest or all versions for a fixed G:A | `maven-metadata.xml` under the artifact directory |
4248
| Inspect dependencies | Fetch and parse the POM for that version |
4349
| 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.
4456

4557
**Search API base:** `https://search.maven.org/solrsearch/select`
4658

4759
**Repository base:** `https://repo1.maven.org/maven2/`
4860

49-
**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
50107

51108
Use HTTP GET with query parameters:
52109

53-
- **`q`** — Solr query. Examples: `g:com.google.guava AND a:guava`, `guava` (broad text), `v:33.0.0`
110+
- **`q`** — Solr query. Examples: `g:org.springframework.boot AND a:spring-boot`, `spring-boot` (broad text), `v:4.0.5`
54111
- **`rows`** — Page size (default 20, max 200)
55112
- **`start`** — Offset for pagination
56113
- **`wt`**`json` (typical) or `xml`
@@ -59,16 +116,18 @@ Use HTTP GET with query parameters:
59116
**Example — search by coordinates:**
60117

61118
```text
62-
https://search.maven.org/solrsearch/select?q=g:com.google.guava+AND+a:guava&rows=20&wt=json
119+
https://search.maven.org/solrsearch/select?q=g:org.springframework.boot+AND+a:spring-boot&rows=20&wt=json
63120
```
64121

65122
**Example — search by keyword:**
66123

67124
```text
68-
https://search.maven.org/solrsearch/select?q=guava&rows=20&wt=json
125+
https://search.maven.org/solrsearch/select?q=spring-boot&rows=20&wt=json
69126
```
70127

71-
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
72131

73132
For a known `groupId` and `artifactId`, version lists and `latest` / `release` hints are published at:
74133

@@ -79,10 +138,12 @@ https://repo1.maven.org/maven2/{groupPath}/{artifactId}/maven-metadata.xml
79138
**Example:**
80139

81140
```text
82-
https://repo1.maven.org/maven2/com/google/guava/guava/maven-metadata.xml
141+
https://repo1.maven.org/maven2/org/springframework/boot/spring-boot/maven-metadata.xml
83142
```
84143

85-
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.
146+
### Step 5: Build direct artifact URLs
86147

87148
Pattern:
88149

@@ -102,21 +163,24 @@ https://repo1.maven.org/maven2/{groupPath}/{artifactId}/{version}/{artifactId}-{
102163
**Example:**
103164

104165
```text
105-
https://repo1.maven.org/maven2/com/google/guava/guava/33.0.0/guava-33.0.0.pom
106-
https://repo1.maven.org/maven2/com/google/guava/guava/33.0.0/guava-33.0.0.jar
107-
https://repo1.maven.org/maven2/com/google/guava/guava/33.0.0/guava-33.0.0-sources.jar
108-
https://repo1.maven.org/maven2/com/google/guava/guava/33.0.0/guava-33.0.0-javadoc.jar
166+
https://repo1.maven.org/maven2/org/springframework/boot/spring-boot/4.0.5/spring-boot-4.0.5.pom
167+
https://repo1.maven.org/maven2/org/springframework/boot/spring-boot/4.0.5/spring-boot-4.0.5.jar
168+
https://repo1.maven.org/maven2/org/springframework/boot/spring-boot/4.0.5/spring-boot-4.0.5-sources.jar
169+
https://repo1.maven.org/maven2/org/springframework/boot/spring-boot/4.0.5/spring-boot-4.0.5-javadoc.jar
109170
```
110171

111-
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
112175

113176
To reason about **direct** and **transitive** dependencies:
114177

115-
1. Download the resolved POM for the chosen GAV (Step 4).
178+
1. Download the resolved POM for the chosen GAV (Step 5).
116179
2. Read `<dependencies>`, `<dependencyManagement>`, and parent `<parent>` (may imply import BOMs or inherited dependencyManagement).
117180
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.
118181

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
120184

121185
**Validation habits:**
122186

@@ -131,23 +195,28 @@ Call out `<scope>`, `<optional>true</optional>`, and `<classifier>` when they af
131195
- Include clickable HTTPS links to Search UI (`https://search.maven.org/`) or direct `repo1.maven.org` paths when useful.
132196
- Mention naming conventions reference: https://maven.apache.org/guides/mini/guide-naming-conventions.html
133197

134-
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
135200

136201
**Task A — Search by name:** `q=<keyword>` on the Search API.
137202

138203
**Task B — Search by G and A:** `q=g:<groupId> AND a:<artifactId>`.
139204

140205
**Task C — Version list / latest:** GET `maven-metadata.xml` for that G:A path.
141206

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.
143210

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`.
212+
### Step 9: Keywords and resources
145213

146-
**English keywords:** maven, maven central, maven repository, dependency, artifact, coordinates, groupId, artifactId, version, POM, JAR, transitive dependencies, dependency tree, search, metadata.
214+
**English keywords:** maven, maven central, maven repository, dependency, artifact, coordinates, groupId, artifactId, version, POM, JAR, transitive dependencies, dependency tree, search, metadata, versions-maven-plugin, display-dependency-updates, display-plugin-updates, display-property-updates, outdated dependencies.
147215

148216
**Resources:**
149217

150218
- Central repository: https://repo1.maven.org/maven2/
151219
- Search UI: https://search.maven.org/
152220
- Search API (Sonatype): https://central.sonatype.com/search-api/
153-
- Naming conventions: https://maven.apache.org/guides/mini/guide-naming-conventions.html
221+
- Naming conventions: https://maven.apache.org/guides/mini/guide-naming-conventions.html
222+
- Versions Maven Plugin: https://www.mojohaus.org/versions/versions-maven-plugin/

0 commit comments

Comments
 (0)