Skip to content

[MSHADE-434] Restore project.getFile() after dependency-reduced POM creation - #827

Open
elharo wants to merge 1 commit into
apache:masterfrom
elharo:fix-MSHADE-434
Open

[MSHADE-434] Restore project.getFile() after dependency-reduced POM creation#827
elharo wants to merge 1 commit into
apache:masterfrom
elharo:fix-MSHADE-434

Conversation

@elharo

@elharo elharo commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Problem

Calling project.setFile(dependencyReducedPomLocation) in ShadeMojo changes the project file reference for all subsequent plugins in the build. This causes plugins like apache-rat-plugin and maven-checkstyle-plugin to resolve relative paths against the wrong directory, breaking their behavior.

Specifically, when dependencyReducedPomLocation is set to a directory other than ${basedir} (e.g., target/), project.getFile() returns the DRP path, and plugins relying on getFile().getParentFile() for basedir resolution will resolve paths incorrectly.

This was introduced/changed by MSHADE-321 (commit 6ea8543) which moved the createDependencyReducedPom() call outside of the inner artifact-processing block.

Fix

Save project.getFile() before calling createDependencyReducedPom() and restore it afterward in ShadeMojo.execute(). This ensures project.getFile() continues to point to the original pom.xml after the shade plugin finishes, preventing side effects on subsequent plugins.

Integration Test

MSHADE-434_ratSideEffect: Configures shade with dependencyReducedPomLocation in target/, then verifies via maven-help-plugin:evaluate that ${project.file} still points to the original pom.xml after shading.

  • Without fix: test fails (project.file is dependency-reduced-pom.xml)
  • With fix: test passes (project.file is pom.xml)

All 72 unit tests pass.

Fixes #453

…reation

Calling project.setFile(dependencyReducedPomLocation) changes the project
file reference for subsequent plugins, causing them to resolve relative
paths against the DRP directory (e.g., target/) instead of the project
basedir. This breaks plugins like apache-rat-plugin and checkstyle that
rely on project.getFile() for path resolution.

Save and restore the original project file around DRP creation to prevent
this side-effect.

Includes integration test MSHADE-434_ratSideEffect that verifies
project.file still points to the original pom.xml after shading.
@elharo
elharo requested a review from Copilot July 29, 2026 13:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Restores MavenProject#getFile() after creating the dependency-reduced POM to prevent side effects on subsequent plugins, and adds an integration test to pin the behavior.

Changes:

  • Save the original project.getFile() before DRP generation and restore it afterward in ShadeMojo.
  • Add an IT project that configures dependencyReducedPomLocation under target/.
  • Add Groovy verification to assert DRP + shaded JAR creation and that ${project.file} remains pom.xml.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java Saves/restores project.file around DRP generation to avoid leaking state to later plugins.
src/it/projects/MSHADE-434_ratSideEffect/verify.groovy Verifies DRP + shaded JAR outputs and checks build log for ${project.file} value.
src/it/projects/MSHADE-434_ratSideEffect/pom.xml Integration-test Maven project reproducing the side-effect scenario and evaluating project.file.
Comments suppressed due to low confidence (1)

src/main/java/org/apache/maven/plugins/shade/mojo/ShadeMojo.java:1

  • project.setFile(originalProjectFile) won’t run if createDependencyReducedPom(artifactIds) (or subsequent logic) throws, so the broken project.file can still leak to later plugins on failure paths. Wrap DRP creation in a try { ... } finally { project.setFile(originalProjectFile); } (and keep the useDependencyReducedPomInJar logic inside the try).
/*

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +39 to +41
def projectFileLine = lines.find { it =~ /^\// && it.endsWith("/pom.xml") }
assert projectFileLine != null : "project.file value not found in build log (expected a path ending with /pom.xml)"
assert projectFileLine.endsWith("/pom.xml") : "project.file should be pom.xml, but was: " + projectFileLine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MSHADE-434] Strange side-effect on rat-plugin

2 participants