Change maven plugin configuration in runtime

Viewed 326

I have two maven plugins, A and B, where A is defined before B.

In the execution of A I want to change a certain configuration of B before it is executed, the two plugins are configured in the same phase (compile).

In the code of plugin A, I get the plugin to which I want to change the configuration:

List<Plugin> plugins = project.getBuildPlugins().stream()
            .filter(plugin -> plugin.getKey().equals("cz.habarta.typescript-generator:typescript-generator-maven-plugin"))
            .collect(Collectors.toList());
    Plugin plugin = plugins.get(0);

where project is a MavenProject instance.

for (PluginExecution t: plugin.getExecutions ()) {
  if (t.getPhase (). equals ("compile")) {
    Xpp3Dom config = (Xpp3Dom) t.getConfiguration ();
    t.setConfiguration (changeConfig (config));
  } else {
    System.out.println ("Not compile phase");
  }
}

The method changeConfig () changes the current configuration and returns a new one.

The configuration is changed, but this change is not taken by the execution of plugin B.

Any subjection?

Update:

The process is as follows, the plugin A scans the project dependencies, for each dependency that meets a series of conditions, the following block must be added to the plugin B configuration:

<moduleDependency>
         <importFrom> value1 </importFrom>
         <importAs> value2 </importAs>
         <infoJson> value3 </infoJson>
          <npmPackageName> value4 </npmVersionRange>
</moduleDependency>

The n blocks are added within the following configuration element of plugin B:

<moduleDependencies>
   ...
</moduleDependencies>

Information about the configuration element of plugin B

The problem is that the new configuration is not taken by plugin B.

Any subjection?

1 Answers

Usually, it is cleaner and easier to set certain properties inside the first plugin and use these properties in the configuration of the second plugin.

Related