Skip to content

dependencyfilesets ignores the mavenProjectId attribute (hardcoded 'maven.project' reference) #371

Description

@elharo

Summary

DependencyFilesetsTask ignores the mavenProjectId attribute: the null-check uses the configurable field, but the actual lookup uses a hardcoded getReference("maven.project"). Setting mavenProjectId to anything other than the default breaks the task, and using the task outside the antrun mojo causes an NPE.

Affected code

src/main/java/org/apache/maven/ant/tasks/DependencyFilesetsTask.java lines 54-61 (master @ 441382c)

if (this.getProject().getReference(mavenProjectId) == null) {
    throw new BuildException("Maven project reference not found: " + mavenProjectId);
}

MavenProject mavenProject = this.getProject().getReference("maven.project");

Problem

Two inconsistencies:

  1. The existence check at line 54 uses the configurable mavenProjectId field, but the project is then fetched with the hardcoded "maven.project" reference at line 58. Setting mavenProjectId to any non-default value therefore either throws a spurious Maven project reference not found: <id> (when that id is not a registered reference), or is silently ignored and the default project is used anyway.
  2. The hardcoded "maven.project" reference is only registered by the AntRunMojo. If the task is invoked standalone (e.g. from an external build.xml via the <ant> task), the reference is null and line 61 mavenProject.getArtifacts() throws an NPE.

Reproduction

<target xmlns:mvn="http://maven.apache.org/ANTRUN">
  <mvn:dependencyfilesets mavenProjectId="nonexistent.ref"/>
</target>

Result: BuildException: Maven project reference not found: nonexistent.ref, although the default maven.project reference exists.

Expected behavior

The attribute should either be honored consistently (both check and lookup) or removed; the lookup should not silently depend on a hardcoded reference id.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions