@@ -1234,6 +1234,17 @@ public void error(String msg, Throwable t) {
12341234 commitIdPropertiesOutputFormat = CommitIdPropertiesOutputFormat .PROPERTIES ;
12351235 }
12361236
1237+ Properties properties = null ;
1238+ // check if properties have already been injected
1239+ Properties contextProperties = getContextProperties (project );
1240+ boolean alreadyInjected = injectAllReactorProjects && contextProperties != null ;
1241+ if (alreadyInjected ) {
1242+ log .info (
1243+ "injectAllReactorProjects is enabled - attempting to use the already computed values" );
1244+ // makes sure the existing context properties are not mutated
1245+ properties = new Properties (contextProperties );
1246+ }
1247+
12371248 final GitCommitIdPlugin .Callback cb =
12381249 new GitCommitIdPlugin .Callback () {
12391250 @ Override
@@ -1339,7 +1350,7 @@ public boolean shouldGenerateGitPropertiesFile() {
13391350
13401351 @ Override
13411352 public void performPublishToAllSystemEnvironments (Properties properties ) {
1342- publishToAllSystemEnvironments (getLogInterface (), properties );
1353+ publishToAllSystemEnvironments (getLogInterface (), properties , contextProperties );
13431354 }
13441355
13451356 @ Override
@@ -1393,29 +1404,27 @@ public boolean shouldPropertiesEscapeUnicode() {
13931404 }
13941405 };
13951406
1396- Properties properties = null ;
1397- // check if properties have already been injected
1398- Properties contextProperties = getContextProperties (project );
1399- boolean alreadyInjected = injectAllReactorProjects && contextProperties != null ;
1400- if (alreadyInjected ) {
1401- log .info (
1402- "injectAllReactorProjects is enabled - attempting to use the already computed values" );
1403- properties = contextProperties ;
1404- }
1405-
14061407 GitCommitIdPlugin .runPlugin (cb , properties );
14071408 } catch (GitCommitIdExecutionException e ) {
14081409 throw new MojoExecutionException (e .getMessage (), e );
14091410 }
14101411 }
14111412
1412- private void publishToAllSystemEnvironments (LogInterface log , Properties propertiesToPublish ) {
1413+ private void publishToAllSystemEnvironments (LogInterface log , Properties propertiesToPublish , Properties contextProperties ) {
14131414 publishPropertiesInto (propertiesToPublish , project .getProperties ());
14141415 // some plugins rely on the user properties (e.g. flatten-maven-plugin)
14151416 publishPropertiesInto (propertiesToPublish , session .getUserProperties ());
14161417
14171418 if (injectAllReactorProjects ) {
1418- appendPropertiesToReactorProjects (log , propertiesToPublish );
1419+ Properties diffPropertiesToPublish = new Properties ();
1420+ propertiesToPublish .forEach ((k , v ) -> {
1421+ if (!contextProperties .contains (k )) {
1422+ diffPropertiesToPublish .setProperty (k .toString (), v .toString ());
1423+ }
1424+ });
1425+ if (!diffPropertiesToPublish .isEmpty ()) {
1426+ appendPropertiesToReactorProjects (log , diffPropertiesToPublish );
1427+ }
14191428 }
14201429
14211430 if (injectIntoSysProperties ) {
@@ -1479,7 +1488,7 @@ private void publishPropertiesInto(Properties propertiesToPublish, Properties pr
14791488 private void appendPropertiesToReactorProjects (LogInterface log , Properties propertiesToPublish ) {
14801489 for (MavenProject mavenProject : reactorProjects ) {
14811490 log .debug ("Adding properties to project: '" + mavenProject .getName () + "'" );
1482-
1491+ if ( mavenProject . equals ( project )) continue ;
14831492 publishPropertiesInto (propertiesToPublish , mavenProject .getProperties ());
14841493 mavenProject .setContextValue (CONTEXT_KEY , propertiesToPublish );
14851494 }
0 commit comments