I have 3 maven projects, the parent, the middle, and the child project:
Parent-->Middle-->Child
Then I have 2 annotation processor dependencies.
The parent project defines maven-compiler-plugin as a managed plugin and configures annotation processor 1 on the annotationProcessorPath. The middle project does likewise and configures annotation processor 2 on the annotationProcessorPath.
Parent-->Middle-->Child | | AP1 AP2
The compile of child project then fails because its missing annotation processor 1, because its configuration comes from middle project. Easy answer is to simply add processor1 to the middle plugin configuration.
What I really want however is for child to inherit the managed configuration from both parent and middle and aggregate them. Maybe it’s just late at night but my gut tells me maven can handle this but I’m missing it.
This is from the parent pom:
<groupId>myproject</groupId> <artifactId>base</artifactId> <version>1.2-SNAPSHOT</version> <build> <pluginManagement> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <annotationProcessorPaths> <path> <groupId>myproject</groupId> <artifactId>annotation1</artifactId> <version>1.0</version> </path> </annotationProcessorPaths> </configuration> </plugin> </plugins> </pluginManagement>
And from the middle pom:
<parent> <groupId>myproject</groupId> <artifactId>base</artifactId> <version>1.2-SNAPSHOT</version> </parent> <artifactId>middle</artifactId> <version>1.1-SNAPSHOT</version> <build> <pluginManagement> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration> <annotationProcessorPaths> <path> <groupId>myproject</groupId> <artifactId>annotation2</artifactId> <version>1.0</version> </path> </annotationProcessorPaths> </configuration> </plugin> </plugins> </pluginManagement>
Can someone show me the technique for a different levels of the hierarchy (parent, middle) to add configuration to the plugin such that the child has the aggregate configuration from both
Advertisement
Answer
It is as following:
Root project – contains pluginManagement section with plugin X and its default configuration
The child project – contains plugin X section; any configuration added in this section is appended to the default configuration of the root (or overwrites – if the same arguments are redefined).
In your case the root should contain pluginManagement with annotation1; the middle should contain plugin with annotation2 (this will be added to the default annotaion1); the child will inherit from the middle the plugin configuration with both annotations.