3

I would like to configure the use of the maven source plugin for all our projects. The way our projects are currently configured we have a parent pom that is inherited by all the projects. So, in order for all projects to use the maven source plugin, I did the following:

  1. Defined the maven source plugin under build -> plugin management in the parent pom

                <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.2.1</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
    
  2. In my project pom (the child pom), I have included the source plugin under build -> plugins

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
        </plugin>

Could someone please tell me if this is the best way to configure this? Is there any way you can avoid specifying the source plugin in the child pom?

IceMan
  • 1,398
  • 16
  • 35
  • Yes, you can avoid specifying the source plugin in each of the child projects. For this you need to put it to `build -> plugins` section of parent pom, not `build -> pluginManagement`. – Andrew Logvinov Dec 17 '12 at 20:14

1 Answers1

4

This is the best way.

To avoid having to add the plugin declaration in the child pom you could add it to the build/plugins section in the parent. The problem with that however is that EVERY child gets that invocation added even if it does not make sense if e.g. the child is a pom or ear packaging. You should therefore not do this..

Manfred Moser
  • 29,539
  • 13
  • 92
  • 123
  • I didn't add it to my comment, but I fully agree with your idea. – Andrew Logvinov Dec 17 '12 at 20:22
  • Thanks, I too agree with the suggestion of not using it blindly with every child project. – IceMan Dec 17 '12 at 21:38
  • @ManfredMoser @AndrewLogvinov Is it possible to do a *conditional* `` in the parent POM, so that it is only done for `jar` child projects? Then one *could* just put it in the parent's `` `` section... – MarnixKlooster ReinstateMonica Aug 22 '14 at 09:35
  • @MarnixKlooster I don't think there's a more or less easy way to do this. I guess easier way would be to set execution for all child modules and skip it where not needed (property `source.skip`). – Andrew Logvinov Aug 22 '14 at 13:44