Skip to content

Commit

Permalink
Merge pull request #306 from aloubyansky/copy-maven-compiler-props
Browse files Browse the repository at this point in the history
Copy Maven compiler properties when generating the Maven plugin module
  • Loading branch information
aloubyansky authored Dec 8, 2023
2 parents 00e81e6 + 1156013 commit d903e8d
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
final Model originalEffectiveModel = new EffectiveModelResolver(nonWorkspaceResolver())
.resolveEffectiveModel(originalCoords);
var effectivePlugins = originalEffectiveModel.getBuild().getPlugins().stream()
.collect(Collectors.toMap(p -> p.getArtifactId(), p -> p));
.collect(Collectors.toMap(Plugin::getArtifactId, p -> p));
int i = 0;
while (i < build.getPlugins().size()) {
var plugin = build.getPlugins().get(i++);
Expand All @@ -1113,6 +1113,9 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
}
}

// copy maven.* properties
copyMavenCompilerProperties(originalEffectiveModel, pom);

var originalDeps = originalEffectiveModel.getDependencies();

final Map<ArtifactKey, String> originalDepVersions = new HashMap<>(originalDeps.size());
Expand Down Expand Up @@ -1159,7 +1162,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
}

// make sure the original properties do not override the platform ones
final Properties originalProps = pom.getProperties();
var originalProps = pom.getProperties();
if (!originalProps.isEmpty()) {
pom.setProperties(new Properties());
for (Map.Entry<?, ?> originalProp : originalProps.entrySet()) {
Expand All @@ -1177,6 +1180,15 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
persistPom(pom);
}

private static void copyMavenCompilerProperties(Model srcModel, Model targetModel) {
var srcProps = srcModel.getProperties();
for (var propName : srcProps.stringPropertyNames()) {
if (propName.startsWith("maven.compiler.")) {
targetModel.getProperties().setProperty(propName, srcProps.getProperty(propName));
}
}
}

private void configureFlattenPlugin(Model pom, boolean updatePomFile, Map<String, String> elementConfig) {
Build build = pom.getBuild();
if (build == null) {
Expand Down

0 comments on commit d903e8d

Please sign in to comment.