How to remove duplicate content from pom.xml for Maven?

I faced this situation: when packing a project using maven, I would like both the source package and the binary package, and they have the same manifest.mf file. Then I have to write the same entry in the plugin configuration maven-source-plugin and maven-jar-plugin, for example:

  <plugins>
             <plugin>
                 <artifactId> maven-source-plugin </artifactId>
                 <executions>
                     <execution>
                         <id> attach-sources </id>
                         <goals>
                             <goal> jar </goal>
                         </goals>
                     </execution>
                 </executions>
                 <configuration>
                     <archive>
                         <manifestEntries>
                             <Artifiact> $ {project.name} </Artifiact>
                             <Version> $ {project.version} </Version>
                             <Vendor> $ {project.organization.name} </Vendor>
                             <Built-By> Shiva Wu </Built-By>
                         </manifestEntries>
                     </archive>
                 </configuration>
             </plugin>
             <plugin>
                 <artifactId> maven-jar-plugin </artifactId>
                 <configuration>
                     <archive>
                         <addMavenDescriptor> false </addMavenDescriptor>
                         <manifestEntries>
                             <Artifiact> $ {project.name} </Artifiact>
                             <Version> $ {project.version} </Version>
                             <Vendor> $ {project.organization.name} </Vendor>
                             <Built-By> Shiva Wu </Built-By>
                         </manifestEntries>
                     </archive>
                 </configuration>
             </plugin>
         </plugins> 
    


It is not possible to change both of them when changing settings. Is there a better way to solve this problem?

Thanks:)

+4
source share
1 answer

There is no better way to handle this than what you are doing.

However, a couple of extra things. You can paste these configurations into the reusable "corporate" or "standard" parent POM in the plugin management section, and then you do not have to specify them again in any other pom. See here for more details:

Best way to exchange Maven pom.xml parts through unrelated projects?

Another thing that I notice is that your personal name should be replaced with a variable that should be set from your settings.xml file. This will help increase assembly portability.

0
source

All Articles