Skip to content

Commit bd86af7

Browse files
committed
Clone POM model before modifying it
1 parent 442cec2 commit bd86af7

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

devtools/maven/src/main/java/io/quarkus/maven/QuarkusBootstrapProvider.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,34 @@ static Map<Path, Model> getProjectMap(MavenSession session) {
104104
return projectModels;
105105
}
106106

107+
/**
108+
* This method is meant to return the "raw" model, i.e. the one that would be obtained
109+
* by reading a {@code pom.xml} file, w/o interpolation, flattening, etc.
110+
* However, plugins, such as, {@code flatten-maven-plugin}, may manipulate raw POMs
111+
* early enough by stripping dependency management, test scoped dependencies, etc,
112+
* to break our bootstrap. So this method attempts to make sure the essential configuration
113+
* is still available to bootstrap a Quarkus app.
114+
*
115+
* @param mp Maven project
116+
* @return raw POM
117+
*/
118+
private static Model getRawModel(MavenProject mp) {
119+
Model model = mp.getOriginalModel();
120+
if (model.getDependencyManagement() == null) {
121+
// clone the model to not modify the original model associated with the project,
122+
// otherwise, the enforcer plugin may fail, for example
123+
model = model.clone();
124+
// this could be the flatten plugin removing the dependencyManagement
125+
// in which case we set the effective dependency management to not lose the platform info
126+
model.setDependencyManagement(mp.getDependencyManagement());
127+
// it also helps to set the effective dependencies in this case
128+
// since the flatten plugin may remove the test dependencies from the POM
129+
model.setDependencies(mp.getDependencies());
130+
}
131+
model.setPomFile(mp.getFile());
132+
return model;
133+
}
134+
107135
private static String getBootstrapProviderId(ArtifactKey moduleKey, String bootstrapId) {
108136
return bootstrapId == null ? moduleKey.toGacString() : moduleKey.toGacString() + "-" + bootstrapId;
109137
}

0 commit comments

Comments
 (0)