From c07c3f14b3bfc76f666f6a1f3c99215ae950fd54 Mon Sep 17 00:00:00 2001 From: Laurent Almeras Date: Wed, 28 Jan 2026 11:36:35 +0100 Subject: [PATCH] issue:983 fix create-from-project / preserveCData / multi-modules When a multi-module project is used with create-from-project with preserveCData, dependencies between modules are broken. For the following hierarchy : * A * B * C -> B The built archetype replace B dependency in C module with a A dependency. This commit adds an integration test triggering the issue and a fix. Fix restore correctly the ${parentArtifactId} value: * before: previous module artifactId is used (so B module setup ${parentArtifactId} B value) * after: original value when entering the method is restored (so B module setup ${parentArticatId} A value) --- .../creator/FilesetArchetypeCreator.java | 8 ++-- .../archetype.properties | 26 +++++++++++ .../invoker.properties | 19 ++++++++ .../projects/issue-983-preserve-cdata/pom.xml | 38 ++++++++++++++++ .../subModule1/pom.xml | 37 +++++++++++++++ .../subModule2/pom.xml | 45 +++++++++++++++++++ .../issue-983-preserve-cdata/verify.groovy | 23 ++++++++++ 7 files changed, 192 insertions(+), 4 deletions(-) create mode 100644 maven-archetype-plugin/src/it/projects/issue-983-preserve-cdata/archetype.properties create mode 100644 maven-archetype-plugin/src/it/projects/issue-983-preserve-cdata/invoker.properties create mode 100644 maven-archetype-plugin/src/it/projects/issue-983-preserve-cdata/pom.xml create mode 100644 maven-archetype-plugin/src/it/projects/issue-983-preserve-cdata/subModule1/pom.xml create mode 100644 maven-archetype-plugin/src/it/projects/issue-983-preserve-cdata/subModule2/pom.xml create mode 100644 maven-archetype-plugin/src/it/projects/issue-983-preserve-cdata/verify.groovy diff --git a/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java b/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java index 7ebddb51..6189d1c8 100644 --- a/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java +++ b/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java @@ -487,8 +487,8 @@ private void createModulePoms( throws IOException, XmlPullParserException { Model pom = pomManager.readPom(FileUtils.resolveFile(basedir, Constants.ARCHETYPE_POM)); - String parentArtifactId = pomReversedProperties.getProperty(Constants.PARENT_ARTIFACT_ID); - String artifactId = pom.getArtifactId(); + String previousParentArtifactId = pomReversedProperties.getProperty(Constants.PARENT_ARTIFACT_ID); + String previousArtifactId = pomReversedProperties.getProperty(Constants.ARTIFACT_ID); setParentArtifactId(pomReversedProperties, pomReversedProperties.getProperty(Constants.ARTIFACT_ID)); setArtifactId(pomReversedProperties, pom.getArtifactId()); @@ -518,8 +518,8 @@ private void createModulePoms( preserveCData, keepParent); - restoreParentArtifactId(pomReversedProperties, parentArtifactId); - restoreArtifactId(pomReversedProperties, artifactId); + restoreParentArtifactId(pomReversedProperties, previousParentArtifactId); + restoreArtifactId(pomReversedProperties, previousArtifactId); } @SuppressWarnings("checkstyle:ParameterNumber") diff --git a/maven-archetype-plugin/src/it/projects/issue-983-preserve-cdata/archetype.properties b/maven-archetype-plugin/src/it/projects/issue-983-preserve-cdata/archetype.properties new file mode 100644 index 00000000..f5b87f16 --- /dev/null +++ b/maven-archetype-plugin/src/it/projects/issue-983-preserve-cdata/archetype.properties @@ -0,0 +1,26 @@ +# 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. + +archetype.groupId=org.codehaus.mojo.archetypes +archetype.artifactId=maven-archetype-test +archetype.version=1.0 +groupId=org.apache.maven.archetype.test +artifactId=test-issue-983-preserve-cdata +version=1.0-SNAPSHOT +package=org.apache.maven.archetype +someProperty=A String to search for +excludePatterns=build.log,invoker.properties,verify.groovy \ No newline at end of file diff --git a/maven-archetype-plugin/src/it/projects/issue-983-preserve-cdata/invoker.properties b/maven-archetype-plugin/src/it/projects/issue-983-preserve-cdata/invoker.properties new file mode 100644 index 00000000..956a3c69 --- /dev/null +++ b/maven-archetype-plugin/src/it/projects/issue-983-preserve-cdata/invoker.properties @@ -0,0 +1,19 @@ +# 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 = org.apache.maven.plugins:maven-archetype-plugin:${project.version}:create-from-project -Darchetype.preserveCData + diff --git a/maven-archetype-plugin/src/it/projects/issue-983-preserve-cdata/pom.xml b/maven-archetype-plugin/src/it/projects/issue-983-preserve-cdata/pom.xml new file mode 100644 index 00000000..b5c95e02 --- /dev/null +++ b/maven-archetype-plugin/src/it/projects/issue-983-preserve-cdata/pom.xml @@ -0,0 +1,38 @@ + + + + + 4.0.0 + + org.apache.maven.archetype.test + test-issue-983-preserve-cdata + 1.0-SNAPSHOT + + Maven archetype Test issue-983-preserve-cdata + pom + + + subModule1 + subModule2 + + diff --git a/maven-archetype-plugin/src/it/projects/issue-983-preserve-cdata/subModule1/pom.xml b/maven-archetype-plugin/src/it/projects/issue-983-preserve-cdata/subModule1/pom.xml new file mode 100644 index 00000000..61474531 --- /dev/null +++ b/maven-archetype-plugin/src/it/projects/issue-983-preserve-cdata/subModule1/pom.xml @@ -0,0 +1,37 @@ + + + + + 4.0.0 + + + org.apache.maven.archetype.test + test-issue-983-preserve-cdata + 1.0-SNAPSHOT + + + test-issue-983-preserve-cdata-subModule1 + Maven archetype Test issue-983-preserve-cdata-subModule1 + pom + + diff --git a/maven-archetype-plugin/src/it/projects/issue-983-preserve-cdata/subModule2/pom.xml b/maven-archetype-plugin/src/it/projects/issue-983-preserve-cdata/subModule2/pom.xml new file mode 100644 index 00000000..c6ad297e --- /dev/null +++ b/maven-archetype-plugin/src/it/projects/issue-983-preserve-cdata/subModule2/pom.xml @@ -0,0 +1,45 @@ + + + + + 4.0.0 + + + org.apache.maven.archetype.test + test-issue-983-preserve-cdata + 1.0-SNAPSHOT + + + test-issue-983-preserve-cdata-subModule2 + Maven archetype Test issue-983-preserve-cdata-subModule2 + pom + + + + org.apache.maven.archetype.test + test-issue-983-preserve-cdata-subModule1 + ${project.version} + + + + diff --git a/maven-archetype-plugin/src/it/projects/issue-983-preserve-cdata/verify.groovy b/maven-archetype-plugin/src/it/projects/issue-983-preserve-cdata/verify.groovy new file mode 100644 index 00000000..d047bb42 --- /dev/null +++ b/maven-archetype-plugin/src/it/projects/issue-983-preserve-cdata/verify.groovy @@ -0,0 +1,23 @@ +/* + * 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 template = new File(basedir, 'target/generated-sources/archetype/src/main/resources/archetype-resources/subModule2/pom.xml') +// dependency subModule1 must be kept +assert template.text.contains('${parentArtifactId}-subModule1') + \ No newline at end of file