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/07/29 13:24:52 UTC
[PR] [MSHADE-434] Restore project.getFile() after dependency-reduced POM creation [maven-shade-plugin]
elharo opened a new pull request, #827:
URL: https://github.com/apache/maven-shade-plugin/pull/827
## 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
--
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] [MSHADE-434] Restore project.getFile() after dependency-reduced POM creation [maven-shade-plugin]
Posted by "github-actions[bot] (via GitHub) via issues" <is...@maven.apache.org>.
github-actions[bot] commented on PR #827:
URL: https://github.com/apache/maven-shade-plugin/pull/827#issuecomment-6648108823
This pull request is stale because it has been waiting for feedback for 60 days. Remove the stale label or comment on this PR, or it will be automatically closed in 30 days.
--
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] [MSHADE-434] Restore project.getFile() after dependency-reduced POM creation [maven-shade-plugin]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #827:
URL: https://github.com/apache/maven-shade-plugin/pull/827#discussion_r3674803269
##########
src/it/projects/MSHADE-434_ratSideEffect/verify.groovy:
##########
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+
+// Verify the dependency-reduced POM was created in the expected location
+File drpFile = new File(basedir, "target/dependency-reduced-pom.xml")
+assert drpFile.isFile() : "DRP should exist at " + drpFile
+
+// Verify the shaded JAR was created
+File shadedJar = new File(basedir, "target/mshade-434-1.0.jar")
+assert shadedJar.isFile() : "Shaded JAR should exist at " + shadedJar
+
+// Verify that project.getFile() was restored to the original pom.xml after shading
+// by checking the build log for the help:evaluate output
+File buildLog = new File(basedir, "../build.log")
+if (!buildLog.isFile()) {
+ buildLog = new File(basedir, "build.log")
+}
+assert buildLog.isFile() : "build.log should exist"
+
+def lines = buildLog.readLines()
+// help:evaluate with forceStdout prints the expression value on its own line
+// Look for a bare absolute path that ends with "/pom.xml" (not "dependency-reduced-pom.xml")
+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
Review Comment:
This verification is Unix-path specific (`^/` and `endsWith(\"/pom.xml\")`) and will fail on Windows agents where absolute paths are typically like `C:\\...\\pom.xml`. Make the match OS-agnostic by allowing both separators and drive prefixes (e.g., normalize `\\` to `/` before checking, or use a regex that supports `([A-Za-z]:)?[\\\\/].*([\\\\/])pom\\.xml$`, or parse the line as a `File` and assert `new File(line).name == 'pom.xml'`).
--
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] [MSHADE-434] Restore project.getFile() after dependency-reduced POM creation [maven-shade-plugin]
Posted by "slachiewicz (via GitHub)" <gi...@apache.org>.
slachiewicz commented on PR #827:
URL: https://github.com/apache/maven-shade-plugin/pull/827#issuecomment-5400926404
The red cell is this PR's own IT, not the change under test. `windows-latest jdk-8-zulu` is the only failing cell; the other 17 are green, and the invoker summary is `Passed: 83, Failed: 1` with `MSHADE-434_ratSideEffect\pom.xml` as the one failure.
`verify.groovy` looks for the `help:evaluate` output like this:
```groovy
def projectFileLine = lines.find { it =~ /^\// && it.endsWith("/pom.xml") }
assert projectFileLine != null
```
Both predicates assume a Unix path. On Windows the value is `D:\a\maven-shade-plugin\...\pom.xml`, which neither starts with `/` nor ends with `/pom.xml`, so `find` returns null and the assert fires before anything about `project.file` is actually checked:
'/home/runner/work/p/pom.xml' -> found = true
'D:\a\...\pom.xml' -> found = false
Matching on the file name instead of the separator fixes it — `it.trim().endsWith("pom.xml") && !it.trim().endsWith("dependency-reduced-pom.xml")` — or compare against `new File(basedir, "pom.xml").canonicalPath`, which is separator-correct by construction.
#828 carries the identical matcher and fails on the same single cell, so one fix covers both.
## On the overlap
#128, this PR, and #828 all address the same thing: `dependencyReducedPomLocation` leaving `project.getFile()` pointing at the reduced POM. #128 changes `setFile` to `setPomFile` so `basedir` is never reassigned; these two save the original and restore it afterwards. Both work, but they are alternatives rather than complements, and #128 has been approved and open since 2022. Worth a maintainer deciding which one lands before either is merged.
*This comment was created with AI assistance.*
--
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