2

Currently I have problems with the configuration inheritance of the Maven Shade Plugin, what I mean by this is that artifactSet and all configuration options "underneath" it turn red whenever I remove the phase and goals options (which are meant to be inherited from the parents pluginManagement section.

I'll show what I have in my parent first and after that what I'm trying to accomplish.

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.4.3</version>

                <executions>
                    <execution>
                        <phase>package</phase>

                        <goals>
                            <goal>shade</goal>
                        </goals>

                        <configuration>
                            <createDependencyReducedPom>false</createDependencyReducedPom>
                        </configuration>
                    </execution>
                </executions>
            <plugin>
        </plugins>
    </pluginManagement>
</build>

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.4.3</version>

                <executions>
                    <execution>
                        <configuration>
                            <artifactSet>
                                <includes>
                                    <include>...</include>
                                </includes>
                            </artifactSet>
                        </configuration>
                    </execution>
                </executions>
            <plugin>
        </plugins>
    </pluginManagement>
</build>
Julian
  • 837
  • 1
  • 11
  • 24
  • What's the actual problem now? I mean after the update – Naman Jan 07 '17 at 04:56
  • I expected the `phase` and `goals` options (which are needed to make the `artifactSet` a valid option to use) to be inherited from the parent, so that I wouldn't have to define them in the child module, but they don't seem to be inherited. What I meant by "which are needed to make the `artifactSet` a valid option to use" is purely based on the errors going away after adding them manually to the child module. – Julian Jan 07 '17 at 04:58
  • The version of the maven-shade-plugin you have defined is wrong cause the most recent version is 2.4.3 and not 3.6.0 – khmarbaise Jan 07 '17 at 07:03
  • Fixed, 3.6.0 is from the maven-compiler-plugin. – Julian Jan 07 '17 at 07:09

1 Answers1

1

1 - You are missing a type <execution> here -

Change

<executions>
    <phase>package</phase>
    <goals>
       <goal>shade</goal>
    </goals>
    <configuration>
       <createDependencyReducedPom>false</createDependencyReducedPom>
    </configuration>
</executions>

to

<executions>
    <execution>
        <phase>package</phase>
        <goals>
            <goal>shade</goal>
        </goals>
        <configuration>
            <createDependencyReducedPom>false</createDependencyReducedPom>
        </configuration>
    </execution>
</executions>

2 - To inherit the configuration from the parent pom.xml, you need to make sure the child pom doesn't define the plugin again within <pluginManagement>. You can remove the tag to inherit the configuration from the parent.

Naman
  • 27,789
  • 26
  • 218
  • 353
  • That's simply me being stupid and not formatting correctly, it isn't the actual problem. – Julian Jan 07 '17 at 04:52
  • It doesn't define the plugin again within the `pluginManagement` tag, but what I think the problem is is that the parent has an `execution` tag inside `executions` and because you can have multiple `execution` tags within `executions` that the child POM inherits the execution but when I add another `execution` it simply assumes I want to add another execution instead of "selecting" an existing one. – Julian Jan 07 '17 at 05:44
  • @Julianv.dBerkmortel which should hold true for any instance of inheritance. – Naman Jan 07 '17 at 05:49
  • 1
    I was able to make my question more specific after I found out about the problem that's causing it and I found out that I can use the `id` tag within an `execution` tag to identify it in the child. But it doesn't seem to work, it still says that the element `artifactSet` is not allowed where I put it after specifying the same `id` tag that I specified in the parent. – Julian Jan 07 '17 at 06:07
  • I guess better would be to set `` to true in parent pom if that's the case. – Naman Jan 07 '17 at 06:14
  • Plugins defined within `pluginManagement` are automatically inherited? – Julian Jan 07 '17 at 06:24
  • Yes. when you define the same groupId and artifactId in the child pom. and executions can be inherited using the tag `` – Naman Jan 07 '17 at 06:39
  • Executions are automatically inherited as well, so I don't get it why it's not working... – Julian Jan 07 '17 at 06:41