This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-dependency-analyzer.git


The following commit(s) were added to refs/heads/master by this push:
     new 2a5b0f6  Refresh documentation for the next release
2a5b0f6 is described below

commit 2a5b0f6d2246ad828883c4e14d0bf8255ca379d7
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Sat Nov 21 17:48:48 2026 +0100

    Refresh documentation for the next release
    
    Moves contributor text out of the README into CONTRIBUTING.md, SECURITY.md 
and AGENTS.md. Drops the Source Xref menu item: no published site has had xref 
pages.
---
 AGENTS.md                                          |  62 +++++++++++++
 CONTRIBUTING.md                                    |  28 ++++++
 README.md                                          |  70 ++++----------
 SECURITY.md                                        |  30 ++++++
 .../analyzer/ProjectDependencyAnalyzer.java        |  20 ++--
 src/site/markdown/index.md.vm                      | 101 +++++++++++++++++++--
 src/site/site.xml                                  |   1 -
 7 files changed, 242 insertions(+), 70 deletions(-)

diff --git a/AGENTS.md b/AGENTS.md
new file mode 100644
index 0000000..89391d7
--- /dev/null
+++ b/AGENTS.md
@@ -0,0 +1,62 @@
+<!---
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+# Agent guide for maven-dependency-analyzer
+
+This file is read by automated agents (security scanners, code
+analyzers, AI assistants) operating on this repository.
+
+## Security
+
+Security model: [SECURITY.md](./SECURITY.md)
+
+Agents that scan this repository should consult `SECURITY.md` and the
+threat model it links before reporting issues.
+
+## Compatibility
+
+The Maven Dependency Plugin and other plugins call this library, so its public
+types are API:
+
+- `ProjectDependencyAnalyzer`, `ClassAnalyzer` and `DependencyAnalyzer` are
+  interfaces that callers may implement. A new method must be a `default` 
method.
+- `ProjectDependencyAnalysis` keeps its deprecated constructors; deprecate,
+  do not remove.
+- Maven core and Resolver are `provided` dependencies pinned to the Maven 3.9
+  line (`mavenVersion`), and Dependabot ignores Maven 3.10 and Resolver 2.x.
+  SLF4J stays on 1.7.x, the line Maven 3 ships, and Mockito on 4.x because 5.x
+  needs Java 11.
+
+## Coding
+
+Use test-first programming. Before fixing a bug or implementing a feature,
+write a test that exposes the bug and verify the test fails.
+
+The bytecode floor is Java 8. Unit tests use JUnit 5 and Mockito; do not add
+JUnit 4, Hamcrest or AssertJ.
+
+Integration tests live in `src/it`. Each one builds a sample project with the
+`setup-mock-plugin`, which writes the analysis to `target/analysis.txt`, and 
its
+`verify.groovy` compares that file with the expected text. Run one IT together
+with the setup project:
+
+```shell
+mvn -P run-its verify -Dinvoker.test=jarWithCompileDependency,setup-mock-plugin
+```
+
+Before submitting a PR, run `mvn spotless:apply` to format the files, then
+`mvn -P run-its verify`. Run Spotless with JDK 17 or 21.
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..36d7f99
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,28 @@
+<!---
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+# Contributing
+
+Read the [Maven developer 
guide](https://maven.apache.org/guides/development/guide-maven-development.html)
+before your first pull request. For this repository:
+
+- Report bugs in [GitHub 
Issues](https://github.com/apache/maven-dependency-analyzer/issues);
+  report security issues privately as [SECURITY.md](SECURITY.md) describes.
+- Discuss new features and API changes on the [dev mailing 
list](https://maven.apache.org/mailing-lists.html) first.
+- Add a unit test or an integration test under `src/it` for every behavior 
change.
+- Run `mvn spotless:apply` and `mvn -P run-its verify` before you push.
+- The pull request title becomes the release note entry, so write it for users.
diff --git a/README.md b/README.md
index 6d96786..97a3215 100644
--- a/README.md
+++ b/README.md
@@ -14,8 +14,8 @@
  See the License for the specific language governing permissions and
  limitations under the License.
 -->
-Contributing to [Apache Maven Dependency 
Analyzer](https://maven.apache.org/shared/maven-dependency-analyzer/)
-======================
+
+# Apache Maven Dependency Analyzer
 
 [![Apache License, Version 2.0, January 
2004](https://img.shields.io/github/license/apache/maven.svg?label=License)][license]
 [![Maven 
Central](https://img.shields.io/maven-central/v/org.apache.maven.shared/maven-dependency-analyzer.svg?label=Maven%20Central)](https://central.sonatype.com/artifact/org.apache.maven.shared/maven-dependency-analyzer)
@@ -24,62 +24,28 @@ Contributing to [Apache Maven Dependency 
Analyzer](https://maven.apache.org/shar
 [![Jenkins 
Tests](https://img.shields.io/jenkins/tests?jobUrl=https%3A%2F%2Fci-maven.apache.org%2Fjob%2FMaven%2Fjob%2Fmaven-box%2Fjob%2Fmaven-dependency-analyzer%2Fjob%2Fmaster%2F)][test-results]
 [![Java 
CI](https://github.com/apache/maven-dependency-analyzer/actions/workflows/maven-verify.yml/badge.svg)][gh-build]
 
-Found a bug or have an idea for a feature? Contributing code is a great way to
-give something back to the open source community. Before you start, read the
-following guidelines. They help maintainers review contributions consistently.
-
-Getting Started
----------------
-
-Before you contribute, complete the following steps:
-
-+ Make sure you have a [GitHub account](https://github.com/signup/free).
-+ If you plan to implement a feature, discuss it on the [dev list][ml-list] 
first.
-  This helps ensure the feature falls within Apache Maven's scope.
-+ Submit a ticket for your issue, if one does not already exist:
-  + Clearly describe the issue, including steps to reproduce when it is a bug.
-  + Include the earliest version in which you observed the issue.
-+ Fork the repository on GitHub.
-
-Making and Submitting Changes
---------------
-
-We accept pull requests through GitHub. The [developer mailing list][ml-list] 
is
-the main channel of communication for contributors.
-
-The following guidelines make pull requests easier to review:
+Finds the unused declared and the used undeclared dependencies of a Maven 
project by reading its
+compiled classes and those of its dependencies. The
+[Maven Dependency 
Plugin](https://maven.apache.org/plugins/maven-dependency-plugin/) uses it for
+`dependency:analyze`; other plugins inject `ProjectDependencyAnalyzer` and call
+`analyze(project)`.
 
-+ Create a topic branch from the branch you want to base your work on, usually 
`master`.
-  Push your changes to that branch in your fork of the repository.
-+ Make logical, self-contained commits.
-+ Use the same [code style][code-style] so that patches show only the actual
-  changes and contain no formatting differences:
-  + Use spaces only for indentation.
-  + Create minimal diffs. Disable save actions such as source reformatting and
-    import organization. If you feel the source code should be reformatted,
-    create a separate PR for this change.
-  + Check for unnecessary whitespace with `git diff --check` before committing.
-+ Add tests for your changes, including JUnit tests and integration tests 
(ITs).
-+ Run all the tests with `mvn -Prun-its verify` to ensure that nothing else 
broke.
-+ Submit a pull request to the repository in the Apache organization.
+The library requires Java 8 and builds against the Maven 3.9 core APIs, which 
the calling plugin's
+Maven runtime provides.
 
-If you plan to contribute regularly, consider filing a [contributor license 
agreement][cla].
+- Documentation: <https://maven.apache.org/shared/maven-dependency-analyzer/>
+- Issues: <https://github.com/apache/maven-dependency-analyzer/issues>
+- Security reports: see [SECURITY.md](SECURITY.md); never a public issue
+- Contributing: see [CONTRIBUTING.md](CONTRIBUTING.md) and 
[AGENTS.md](AGENTS.md)
 
-Additional Resources
---------------------
+## Build
 
-+ [Contributing 
patches](https://maven.apache.org/guides/development/guide-maven-development.html#Creating_and_submitting_a_patch)
-+ [Contributor License Agreement][cla]
-+ [General GitHub documentation](https://docs.github.com/)
-+ [GitHub pull request 
documentation](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request)
-+ [Apache Maven X account](https://x.com/ASFMavenProject)
-+ [Apache Maven Bluesky account](https://bsky.app/profile/maven.apache.org)
-+ [Apache Maven Mastodon 
account](https://mastodon.social/deck/@[email protected])
+```shell
+mvn verify
+mvn -P run-its verify
+```
 
 [license]: https://www.apache.org/licenses/LICENSE-2.0
-[ml-list]: https://maven.apache.org/mailing-lists.html
-[code-style]: https://maven.apache.org/developers/conventions/code.html
-[cla]: https://www.apache.org/licenses/#clas
 [test-results]: 
https://ci-maven.apache.org/job/Maven/job/maven-box/job/maven-dependency-analyzer/job/master/lastCompletedBuild/testReport/
 [build]: 
https://ci-maven.apache.org/job/Maven/job/maven-box/job/maven-dependency-analyzer/job/master/
 [gh-build]: 
https://github.com/apache/maven-dependency-analyzer/actions/workflows/maven-verify.yml?query=branch%3Amaster
diff --git a/SECURITY.md b/SECURITY.md
new file mode 100644
index 0000000..72fd0d1
--- /dev/null
+++ b/SECURITY.md
@@ -0,0 +1,30 @@
+<!---
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+
+# Security policy
+
+## Report a vulnerability
+
+`apache/maven-dependency-analyzer` follows the [Apache Software Foundation 
security process](https://www.apache.org/security/).
+Report suspected vulnerabilities privately to `[email protected]`; do not 
open public
+GitHub issues or pull requests for security reports.
+
+## Threat model
+
+What the project treats as in scope and out of scope, the security
+properties it provides and disclaims, the adversary model, and how
+findings are triaged are documented in 
<https://github.com/apache/maven/blob/master/THREAT_MODEL.md>.
diff --git 
a/src/main/java/org/apache/maven/shared/dependency/analyzer/ProjectDependencyAnalyzer.java
 
b/src/main/java/org/apache/maven/shared/dependency/analyzer/ProjectDependencyAnalyzer.java
index 4b0d84a..060f322 100644
--- 
a/src/main/java/org/apache/maven/shared/dependency/analyzer/ProjectDependencyAnalyzer.java
+++ 
b/src/main/java/org/apache/maven/shared/dependency/analyzer/ProjectDependencyAnalyzer.java
@@ -36,23 +36,25 @@ import org.apache.maven.project.MavenProject;
 public interface ProjectDependencyAnalyzer {
 
     /**
-     * <p>analyze.</p>
+     * Analyzes the dependencies of a project. The project's main and test 
classes must be compiled and its
+     * dependencies resolved in the test scope.
      *
-     * @param project a {@link org.apache.maven.project.MavenProject} object
-     * @return a {@link 
org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalysis} object
-     * @throws 
org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalyzerException 
if any
+     * @param project the project to analyze
+     * @return the analysis result
+     * @throws ProjectDependencyAnalyzerException if the classes of the 
project or of a dependency cannot be read
      */
     default ProjectDependencyAnalysis analyze(MavenProject project) throws 
ProjectDependencyAnalyzerException {
         return analyze(project, null);
     }
 
     /**
-     * <p>analyze.</p>
+     * Analyzes the dependencies of a project, leaving out the classes that 
match {@code excludedClasses} both in the
+     * project and in its dependencies.
      *
-     * @param project a {@link org.apache.maven.project.MavenProject} object
-     * @param excludedClasses collection of regular expression of classes name 
to exclude
-     * @return a {@link 
org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalysis} object
-     * @throws 
org.apache.maven.shared.dependency.analyzer.ProjectDependencyAnalyzerException 
if any
+     * @param project the project to analyze
+     * @param excludedClasses regular expressions of class names to exclude, 
or {@code null} for none
+     * @return the analysis result
+     * @throws ProjectDependencyAnalyzerException if the classes of the 
project or of a dependency cannot be read
      */
     ProjectDependencyAnalysis analyze(MavenProject project, Collection<String> 
excludedClasses)
             throws ProjectDependencyAnalyzerException;
diff --git a/src/site/markdown/index.md.vm b/src/site/markdown/index.md.vm
index fc9b301..3076e51 100644
--- a/src/site/markdown/index.md.vm
+++ b/src/site/markdown/index.md.vm
@@ -19,17 +19,102 @@ under the License.
 
 # ${project.name}
 
-Analyzes the dependencies of a project for undeclared or unused artifacts.
+Analyzes the dependencies of a Maven project and reports which declared 
dependencies are unused
+and which used dependencies are not declared. The
+[Maven Dependency 
Plugin](https://maven.apache.org/plugins/maven-dependency-plugin/) uses it for 
the
+`dependency:analyze` goals.
 
-**Warning**: Because analysis is done on the bytecode rather than the source,
-some cases are not detected, including annotations with source-only retention
-and links in Javadoc. This can lead to incorrect results when these are the 
only uses
-of a dependency. Inlined constants are detected: javac and ecj record the 
constant's
-declaring class in the constant pool, which the analyzer reads.
+The analysis reads the project's compiled classes and the class files of its 
resolved
+dependencies, so run it after the `test-compile` phase, with test-scoped 
dependencies resolved. A missing
+output directory is not an error: run too early, the analysis sees no classes 
and reports every
+declared dependency as unused.
+The library requires Java 8 and is compiled against the Maven ${mavenVersion} 
core APIs, which the
+calling plugin's Maven runtime provides.
+
+## Usage
+
+Add the dependency to a Maven plugin:
+
+```xml
+<dependency>
+  <groupId>${project.groupId}</groupId>
+  <artifactId>${project.artifactId}</artifactId>
+  <version>${project.version}</version>
+</dependency>
+```
+
+Inject `ProjectDependencyAnalyzer` and pass it the current project:
+
+```java
+@Mojo(name = "analyze", requiresDependencyResolution = ResolutionScope.TEST)
+public class AnalyzeMojo extends AbstractMojo {
+    @Inject
+    private ProjectDependencyAnalyzer analyzer;
+
+    @Inject
+    private MavenProject project;
+
+    @Override
+    public void execute() throws MojoExecutionException {
+        try {
+            ProjectDependencyAnalysis analysis = analyzer.analyze(project);
+            analysis.getUnusedDeclaredArtifacts().forEach(a -> 
getLog().warn("Unused declared: " + a));
+            analysis.getUsedUndeclaredArtifacts().forEach(a -> 
getLog().warn("Used undeclared: " + a));
+        } catch (ProjectDependencyAnalyzerException e) {
+            throw new MojoExecutionException("Dependency analysis failed", e);
+        }
+    }
+}
+```
+
+`analyze(project, excludedClasses)` takes regular expressions of class names 
to leave out of the
+analysis, both in the project's own classes and in the dependencies.
+
+## Results
+
+`ProjectDependencyAnalysis`
+([javadoc](./apidocs/org/apache/maven/shared/dependency/analyzer/ProjectDependencyAnalysis.html))
+holds the result:
+
+| Method | Returns |
+|---|---|
+| `getUsedDeclaredArtifacts()` | Declared dependencies that the bytecode uses |
+| `getUsedUndeclaredArtifacts()` | Dependencies that the bytecode uses but the 
POM does not declare, such as transitive ones |
+| `getUnusedDeclaredArtifacts()` | Declared dependencies that the bytecode 
does not use |
+| `getTestArtifactsWithNonTestScope()` | Compile-scoped dependencies that only 
tests use and that no other compile or runtime dependency brings in |
+| `getUsedDeclaredArtifactsWithUsages()`, 
`getUsedUndeclaredArtifactsWithUsages()` | The same artifacts with each used 
class and the project class (or `web.xml`) that uses it |
+| `getUsedDependencyClasses()`, `getCandidateArtifactsByUsedClass()`, 
`getSelectedArtifactByUsedClass()` | Every class the bytecode references, every 
dependency that contains it, and the dependency the analysis credited (since 
1.18.0) |
+| `getAmbiguousUsedDependencyClasses()`, `getUnmappedUsedDependencyClasses()` 
| Referenced classes found in more than one dependency, and referenced classes 
found in none; the latter include JDK and project classes (since 1.18.0) |
+
+`ignoreNonCompile()` drops dependencies outside the compile scope from the 
unused list, and
+`forceDeclaredDependenciesUsage(String[])` moves the given 
`groupId:artifactId` entries from unused
+to used. It fails when an entry is not declared or is already used, so stale 
entries do not linger.
+
+## How classes are credited
+
+- When several artifacts contain a used class, a declared artifact is credited 
over an undeclared
+  one, and among those the first one found. Scope is not considered: a 
declared test-scoped artifact
+  is credited even for a class that main code uses.
+- A declared JAR without classes of its own counts as used when an artifact it 
brings in directly
+  is used. That artifact is then not reported as used undeclared.
+- In a `war` project, the filter, listener and servlet classes named in 
`web.xml` (the war plugin's `webXml`, by default 
`src/main/webapp/WEB-INF/web.xml`) count as
+  used.
+- Inlined constants are detected: javac and ecj record the constant's 
declaring class in the
+  constant pool, which the analyzer reads.
+
+## Limitations
+
+The analysis works on bytecode, not on source. It cannot see annotations with 
source-only
+retention, links in Javadoc, or classes named only in strings, such as 
`Class.forName` arguments
+or `META-INF/services` entries; `web.xml` is the one text file it reads. When 
these are the only uses of a dependency, it is reported as
+unused; `forceDeclaredDependenciesUsage` is the escape hatch.
+
+## Components
 
 The main component is `ProjectDependencyAnalyzer`
 
([javadoc](./apidocs/org/apache/maven/shared/dependency/analyzer/ProjectDependencyAnalyzer.html)),
 which uses
 `ClassAnalyzer`
 
([javadoc](./apidocs/org/apache/maven/shared/dependency/analyzer/ClassAnalyzer.html))
-and `DependencyAnalyzer`
-([javadoc](./apidocs/org/apache/maven/shared/dependency/analyzer/DependencyAnalyzer.html)).
+to list the classes in each artifact and `DependencyAnalyzer`
+([javadoc](./apidocs/org/apache/maven/shared/dependency/analyzer/DependencyAnalyzer.html))
+to collect the classes that the project's bytecode references.
diff --git a/src/site/site.xml b/src/site/site.xml
index c69dcd5..0037dba 100644
--- a/src/site/site.xml
+++ b/src/site/site.xml
@@ -25,7 +25,6 @@ under the License.
     <menu name="Overview">
       <item name="Introduction" href="index.html"/>
       <item name="JavaDocs" href="apidocs/index.html"/>
-      <item name="Source Xref" href="xref/index.html"/>
       <!--item name="FAQ" href="faq.html"/-->
       <!-- According to https://issues.apache.org/jira/browse/MNGSITE-152 -->
       <item name="License" href="https://www.apache.org/licenses/"/>

Reply via email to