From d7b316a1029eb699ef01d4239271b9cdf291dec8 Mon Sep 17 00:00:00 2001 From: opencode Date: Wed, 29 Jul 2026 13:23:22 +0000 Subject: [PATCH] [MPH-217] Ensure packaging is always shown in effective-pom output MavenXpp3Writer omits the packaging element when it is null or equals the default value 'jar'. This leads help:effective-pom to not show the packaging at all when it is not explicitly set in the POM. Fix: after serialization, insert the packaging element into the XML output if missing. This ensures users can always see the effective packaging value (e.g. jar, pom, war) in the effective POM output. Includes an integration test with a POM that has no packaging element, verifying the output contains jar. --- .../invoker.properties | 18 ++++++++++++ .../projects/effective-pom-packaging/pom.xml | 29 +++++++++++++++++++ .../effective-pom-packaging/verify.groovy | 25 ++++++++++++++++ .../maven/plugins/help/EffectivePomMojo.java | 10 +++++++ 4 files changed, 82 insertions(+) create mode 100644 src/it/projects/effective-pom-packaging/invoker.properties create mode 100644 src/it/projects/effective-pom-packaging/pom.xml create mode 100644 src/it/projects/effective-pom-packaging/verify.groovy diff --git a/src/it/projects/effective-pom-packaging/invoker.properties b/src/it/projects/effective-pom-packaging/invoker.properties new file mode 100644 index 00000000..adecbad1 --- /dev/null +++ b/src/it/projects/effective-pom-packaging/invoker.properties @@ -0,0 +1,18 @@ +# 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. + +invoker.goals = ${project.groupId}:${project.artifactId}:${project.version}:effective-pom diff --git a/src/it/projects/effective-pom-packaging/pom.xml b/src/it/projects/effective-pom-packaging/pom.xml new file mode 100644 index 00000000..6622e253 --- /dev/null +++ b/src/it/projects/effective-pom-packaging/pom.xml @@ -0,0 +1,29 @@ + + + + + + 4.0.0 + + org.apache.maven.its.help + mph-217 + 1.0-SNAPSHOT + + diff --git a/src/it/projects/effective-pom-packaging/verify.groovy b/src/it/projects/effective-pom-packaging/verify.groovy new file mode 100644 index 00000000..abb1affa --- /dev/null +++ b/src/it/projects/effective-pom-packaging/verify.groovy @@ -0,0 +1,25 @@ +/* + * 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. + */ +def buildLog = new File(basedir, 'build.log'); +assert buildLog.exists() + +def LS = System.getProperty("line.separator") +assert buildLog.text.find( + '(?s)' + + ' jar') != null diff --git a/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java b/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java index 4fa115c2..45dbffbc 100644 --- a/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java +++ b/src/main/java/org/apache/maven/plugins/help/EffectivePomMojo.java @@ -197,6 +197,16 @@ private void writeEffectivePom(MavenProject project, XMLWriter writer) throws Mo // This removes the XML declaration written by MavenXpp3Writer String effectivePom = prettyFormat(sWriter.toString(), null, true); + // MavenXpp3Writer omits packaging when it is null or "jar" (the default). + // Ensure it is always present so users can see the effective packaging value. + if (pom.getPackaging() == null || "jar".equals(pom.getPackaging())) { + String packaging = pom.getPackaging() != null ? pom.getPackaging() : project.getPackaging(); + String packagingTag = " " + packaging + ""; + if (!effectivePom.contains(packagingTag)) { + effectivePom = effectivePom.replace("" + LS, "" + LS + packagingTag + LS); + } + } + writeComment(writer, "Effective POM for project '" + project.getId() + "'"); writer.writeMarkup(effectivePom);