You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "elharo (via GitHub)" <gi...@apache.org> on 2026/09/29 11:51:55 UTC

[PR] Replace deprecated ArtifactRepository with resolver API [maven-antrun-plugin]

elharo opened a new pull request, #394:
URL: https://github.com/apache/maven-antrun-plugin/pull/394

   `org.apache.maven.artifact.repository.ArtifactRepository` is deprecated. Its javadoc says:
   
   > Avoid use of this type, if you need access to local repository use repository system classes instead.
   
   This does that. The local repository now comes from the `RepositorySystemSession`, which is available on every Maven version this plugin supports (`maven` prerequisite is 3.6.3, and `${repositorySystemSession}` plus `RepositorySystemSession#getLocalRepository()` / `#getLocalRepositoryManager()` all exist in the resolver version shipped with it).
   
   The deprecated type was used in three places, so all three are affected.
   
   ## `DependencyFilesetsTask`
   
   The `maven.local.repository` Ant reference now holds an `org.eclipse.aether.repository.LocalRepository`. `LocalRepository` has no path-computation method, so a second reference, `maven.local.repository.manager`, exposes the `LocalRepositoryManager` for `getPathForLocalArtifact()`.
   
   `ArtifactRepository#pathOf()` has no direct equivalent on `LocalRepository`, so the task now calls `LocalRepositoryManager#getPathForLocalArtifact(RepositoryUtils.toArtifact(artifact))`. These apply the same layout rules, including the SNAPSHOT case where the directory uses the base version but the filename uses the resolved version.
   
   ## The two Ant properties
   
   - `${settings.localRepository}` — **unchanged**, still the absolute path of the local repository.
   - `${localRepository}` — **value changes.** It was `ArtifactRepository#toString()`, a multi-line debug dump whose first line read `id: local`; it is not usable as a path. It is now the same absolute path that `${settings.localRepository}` provides.
   
   Neither property is documented on the site, and `local-repo-prop-test` only asserts they are set, but this is visible to anyone referencing `${localRepository}`.
   
   ## Other change
   
   The `@Parameter(property = "localRepository")` hook went away with the field. It allowed `-DlocalRepository=...` to override the repository the plugin used, which cannot be expressed as a repository system session, and was not documented.
   
   ## Verification
   
   - Before: 4 deprecation warnings for `ArtifactRepository` (the import and field in `AntRunMojo`, the import and local-variable type in `DependencyFilesetsTask`). After: none. The two remaining warnings are the unrelated `org.codehaus.plexus.util.ReaderFactory` ones.
   - `mvn clean verify`: BUILD SUCCESS, 0 Checkstyle violations, Spotless clean, 4/4 unit tests.
   - All 29 ITs pass via `mvn invoker:install invoker:run`.
   - To check that swapping `pathOf()` for `getPathForLocalArtifact()` resolves the same files, I built the same project against the old and new plugin and copied out the `maven.project.dependencies` fileset. The resulting trees are **identical** (41 files), covering the cases where the two could have diverged: a release, a SNAPSHOT, a classifier (`json-lib:2.4:jdk15`), a `pom`-typed dependency, and a `classes`-extension artifact.
   
   ## Note for maintainers
   
   The `protected ArtifactRepository localRepository` field became a `protected LocalRepository getLocalRepository()` method, and the Ant reference type changed. Both are breaking for anyone subclassing `AntRunMojo` or reading `maven.local.repository` as an `ArtifactRepository` from a custom Ant task. That seemed unavoidable given the type is deprecated, but flagging it in case a `@Deprecated`-and-removed cycle is preferred.
   
   `ReaderFactory` is also deprecated (2 warnings) and could be dealt with in a follow-up.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Replace deprecated ArtifactRepository with resolver API [maven-antrun-plugin]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #394:
URL: https://github.com/apache/maven-antrun-plugin/pull/394#discussion_r4134653347


##########
src/main/java/org/apache/maven/ant/tasks/DependencyFilesetsTask.java:
##########
@@ -62,8 +63,9 @@ public void execute() {
 
         FileSet dependenciesFileSet = new FileSet();
         dependenciesFileSet.setProject(getProject());
-        ArtifactRepository localRepository = getProject().getReference("maven.local.repository");
-        dependenciesFileSet.setDir(new File(localRepository.getBasedir()));
+        LocalRepository localRepository = getProject().getReference("maven.local.repository");
+        LocalRepositoryManager localRepositoryManager = getProject().getReference("maven.local.repository.manager");

Review Comment:
   The Ant reference IDs are duplicated here as string literals, and one of them (`maven.local.repository.manager`) is newly introduced. To avoid drift between producer (`AntRunMojo`) and consumer (`DependencyFilesetsTask`), consider centralizing these keys (e.g., `public static final` constants in a shared class) and referencing the constants from both locations.



##########
src/main/java/org/apache/maven/plugins/antrun/AntRunMojo.java:
##########
@@ -424,8 +436,12 @@ public void copyProperties(MavenProject mavenProject, Project antProject) {
         antProject.setProperty(
                 (propertyPrefix + "project.build.testSourceDirectory"),
                 mavenProject.getBuild().getTestSourceDirectory());
-        antProject.setProperty((propertyPrefix + "localRepository"), localRepository.toString());
-        antProject.setProperty((propertyPrefix + "settings.localRepository"), localRepository.getBasedir());
+        antProject.setProperty(
+                (propertyPrefix + "localRepository"),
+                getLocalRepository().getBasedir().getAbsolutePath());

Review Comment:
   This line changes `${localRepository}` semantics from a debug `toString()` dump to an absolute filesystem path. Since this is externally observable in Ant builds, it should be covered by an integration/unit test assertion (e.g., that `${localRepository}` equals `${settings.localRepository}` and points to an existing directory) to prevent accidental regression.



##########
src/main/java/org/apache/maven/plugins/antrun/AntRunMojo.java:
##########
@@ -350,7 +360,9 @@ private void addAntProjectReferences(MavenProject mavenProject, Project antProje
         antProject.addReference(DEFAULT_MAVEN_PROJECT_REFID, mavenProject);
         antProject.addReference(DEFAULT_MAVEN_PROJECT_REF_REFID, new MavenAntRunProject(mavenProject));
         antProject.addReference(DEFAULT_MAVEN_PROJECT_HELPER_REFID, projectHelper);
-        antProject.addReference(MAVEN_REFID_PREFIX + "local.repository", localRepository);
+        antProject.addReference(MAVEN_REFID_PREFIX + "local.repository", getLocalRepository());

Review Comment:
   This changes the runtime type of the `maven.local.repository` Ant reference from `ArtifactRepository` to `LocalRepository`, which will cause `ClassCastException` in custom Ant tasks or builds that still cast that reference to `ArtifactRepository`. To reduce the breaking impact, consider publishing an additional (new) reference key for the resolver types (e.g., `maven.local.repository.resolver` / `...manager`) while keeping `maven.local.repository` as a backward-compatible value (such as the local repo basedir `File`), or add a deprecated compatibility shim cycle (even if internally backed by resolver APIs).



##########
src/main/java/org/apache/maven/plugins/antrun/AntRunMojo.java:
##########
@@ -424,8 +436,12 @@ public void copyProperties(MavenProject mavenProject, Project antProject) {
         antProject.setProperty(
                 (propertyPrefix + "project.build.testSourceDirectory"),
                 mavenProject.getBuild().getTestSourceDirectory());
-        antProject.setProperty((propertyPrefix + "localRepository"), localRepository.toString());
-        antProject.setProperty((propertyPrefix + "settings.localRepository"), localRepository.getBasedir());
+        antProject.setProperty(
+                (propertyPrefix + "localRepository"),
+                getLocalRepository().getBasedir().getAbsolutePath());
+        antProject.setProperty(
+                (propertyPrefix + "settings.localRepository"),
+                getLocalRepository().getBasedir().getAbsolutePath());

Review Comment:
   The local-repo absolute path is computed twice. Capture `getLocalRepository().getBasedir().getAbsolutePath()` into a local variable (or compute `LocalRepository` once) and reuse it for both properties to avoid duplication and make future edits less error-prone.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Replace deprecated ArtifactRepository with resolver API [maven-antrun-plugin]

Posted by "elharo (via GitHub)" <gi...@apache.org>.
elharo merged PR #394:
URL: https://github.com/apache/maven-antrun-plugin/pull/394


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@maven.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org