diff --git a/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java b/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java index 5eae4976..d30447e2 100644 --- a/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java +++ b/src/main/java/pl/project13/maven/git/GitCommitIdMojo.java @@ -1234,6 +1234,17 @@ public void error(String msg, Throwable t) { commitIdPropertiesOutputFormat = CommitIdPropertiesOutputFormat.PROPERTIES; } + Properties properties = null; + // check if properties have already been injected + Properties contextProperties = getContextProperties(project); + boolean alreadyInjected = injectAllReactorProjects && contextProperties != null; + if (alreadyInjected) { + log.info( + "injectAllReactorProjects is enabled - attempting to use the already computed values"); + // makes sure the existing context properties are not mutated + properties = new Properties(contextProperties); + } + final GitCommitIdPlugin.Callback cb = new GitCommitIdPlugin.Callback() { @Override @@ -1339,7 +1350,7 @@ public boolean shouldGenerateGitPropertiesFile() { @Override public void performPublishToAllSystemEnvironments(Properties properties) { - publishToAllSystemEnvironments(getLogInterface(), properties); + publishToAllSystemEnvironments(getLogInterface(), properties, contextProperties); } @Override @@ -1393,29 +1404,27 @@ public boolean shouldPropertiesEscapeUnicode() { } }; - Properties properties = null; - // check if properties have already been injected - Properties contextProperties = getContextProperties(project); - boolean alreadyInjected = injectAllReactorProjects && contextProperties != null; - if (alreadyInjected) { - log.info( - "injectAllReactorProjects is enabled - attempting to use the already computed values"); - properties = contextProperties; - } - GitCommitIdPlugin.runPlugin(cb, properties); } catch (GitCommitIdExecutionException e) { throw new MojoExecutionException(e.getMessage(), e); } } - private void publishToAllSystemEnvironments(LogInterface log, Properties propertiesToPublish) { + private void publishToAllSystemEnvironments(LogInterface log, Properties propertiesToPublish, Properties contextProperties) { publishPropertiesInto(propertiesToPublish, project.getProperties()); // some plugins rely on the user properties (e.g. flatten-maven-plugin) publishPropertiesInto(propertiesToPublish, session.getUserProperties()); if (injectAllReactorProjects) { - appendPropertiesToReactorProjects(log, propertiesToPublish); + Properties diffPropertiesToPublish = new Properties(); + propertiesToPublish.forEach((k, v) -> { + if (!contextProperties.contains(k)) { + diffPropertiesToPublish.setProperty(k.toString(), v.toString()); + } + }); + if(!diffPropertiesToPublish.isEmpty()) { + appendPropertiesToReactorProjects(log, diffPropertiesToPublish); + } } if (injectIntoSysProperties) { @@ -1479,7 +1488,7 @@ private void publishPropertiesInto(Properties propertiesToPublish, Properties pr private void appendPropertiesToReactorProjects(LogInterface log, Properties propertiesToPublish) { for (MavenProject mavenProject : reactorProjects) { log.debug("Adding properties to project: '" + mavenProject.getName() + "'"); - + if(mavenProject.equals(project)) continue; publishPropertiesInto(propertiesToPublish, mavenProject.getProperties()); mavenProject.setContextValue(CONTEXT_KEY, propertiesToPublish); }